RE: init_completion, down(mutex) related question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Title: Message
 
 Hello All,

I am new to the Linux Kernel programming, and still learning the OS concepts. (but project deadlines dont consider it u know ;-)

Can anyone explain why do we write driver code like this :
static void s3c24a0_ac97_write(struct ac97_codec *codec, u8 reg, u16 val)

{

        down(&CAR_mutex);    //ACQUIRE SEMAPHORE // 

        init_completion(&CAR_completion);  //MAKE CODE ATOMIC // 

        AC_CODEC_CMD = AC_CMD_ADDR(reg) | AC_CMD_DATA(val);   //CRITICAL SECTION // 

        wait_for_completion(&CAR_completion);   

        up(&CAR_mutex);  //RELEASE SEAMPHORE // 

}

why it cant be written as

static void s3c24a0_ac97_write(struct ac97_codec *codec, u8 reg, u16 val)

{

        AC_CODEC_CMD = AC_CMD_ADDR(reg) | AC_CMD_DATA(val);

}

what is the meaning of down,up,completion etc.

see the commnets embedded above hope that helps you are trying to change the value of a variable which may be read or write by any other process so acquiring it using a semaphore and then after completing the opn.. releasing semaphore .

 Someone Please correct me if i am wrong  ?

 Thanks and Regards,

Shiv Kumar Garg

Senior Software Engineer

System LSI Division

Samsung India Software Operation

3/1 Millers Road, Bangalore

Phone: +91-80-51197777 ext 2018

email: shivg@samsung.com

_________________________________

Well done is better than Well said


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux