Re: init_completion, down(mutex) related question

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

 



down and up primitives are used to acquire and release a semaphore, mutex or
any synchronization primitive. init_completion will initialize wait queue
and one flag, so that the wait queue can be used later (in
wait_for_completion). wait_for_completion puts the task into the wait queue
and invokes if the flag is set.
This all you need to do if some part of code is being accessed in more than
one context. It could be kernel context and interrupt context, or your code
might be running in multi processor machine.

Regards
Mohanlal

----- Original Message -----
From: "Shiv Garg" <shivg@samsung.com>
To: <kernelnewbies@nl.linux.org>
Sent: Thursday, July 01, 2004 7:24 PM
Subject: init_completion, down(mutex) related question


> Hello All,
> I am new to the Linux Kernel programming, and still learning the OS
> concepts. (but project deadlines don't 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);
> init_completion(&CAR_completion);
>
> AC_CODEC_CMD = AC_CMD_ADDR(reg) | AC_CMD_DATA(val);
>
> wait_for_completion(&CAR_completion);
> up(&CAR_mutex);
> }
>
> 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.
>
> 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
>
>


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[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