Re: Semaphore

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

 



On Fri, Jan 03, 2003 at 10:58:56AM +0530, Rupa wrote:
> Hello,
>    I have used semaphore for locking in my kernel module. It is working fine. I am able to compile and install the module.
>    I have just used asm/semaphore.h in my include files. 
> Rupa
> ----- Original Message ----- 
>   From: S P 
>   To: kernelnewbies@nl.linux.org 
>   Sent: Friday, January 03, 2003 2:12 AM
>   Subject: Semaphore
> 
> 
>   Hi,
> 
>   I am trying to use semaphore for locking. Following is the piece of code I am using :
> 
>   struct semaphore mr_sem;
> 
>   sema_init(&mr_sem, 1); /* usage count is 1 */
> 
>   if (down_interruptible(&mr_sem))
>     /* semaphore not acquired; received a signal ... */
> 
>   /* critical region (semaphore acquired) ... */
> 
>   up(&mr_sem);
> 
> 
> 
>   The compilation is done using gcc with options _D__KERNEL__. It compiles properly, but the linking gives some errors regards to __down_failed_interruptible and __up_wakeup.
> 
>   Do I need to specify some other options for the compilation.

IIRC you need -DMODULE too. IIRC you may need -O2. Personaly I use
following mad commad to get CFLAGS kernel itself is compiled with:

CFLAGS+= $(shell $(MAKE) -s -C $(LINUX) script 'SCRIPT=echo $$(CFLAGS)') 
CFLAGS+= -DMODULE

Where $(LINUX) expands to path to kernel source. This should not be
needed to build modules for kernel on sane architectures, but on some,
like the 'um' arch is's the sanest way.

Just a sanity check: first thing you need to include is linux/kernel.h
and linux/module.h.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
--
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