why so little usage of DEFINE_SEMAPHORE()?

Robert P. J. Day rpjday at crashcourse.ca
Sat Sep 29 09:24:14 EDT 2012

  following up on my earlier post, i'm summarizing the current use of
semaphores in the kernel and quite a lot of docs are going to have to
cleanse themselves of now-obsolete references to all of
DECLARE_MUTEX[_LOCKED] and init_MUTEX[_LOCKED], since the current API
consists simply of:

  * sema_init()

but a quick grep for the former produces only:

drivers/macintosh/adb.c:static DEFINE_SEMAPHORE(adb_probe_mutex);
drivers/staging/comedi/drivers/usbduxfast.c:static DEFINE_SEMAPHORE(start_stop_sem);
drivers/staging/comedi/drivers/usbduxsigma.c:static DEFINE_SEMAPHORE(start_stop_sem);
drivers/staging/comedi/drivers/dt9812.c:static DEFINE_SEMAPHORE(dt9812_mutex);
drivers/staging/comedi/drivers/usbdux.c:static DEFINE_SEMAPHORE(start_stop_sem);
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c:static DEFINE_SEMAPHORE(bnx2x_prev_sem);
include/linux/semaphore.h:#define DEFINE_SEMAPHORE(name)	\
kernel/printk.c:static DEFINE_SEMAPHORE(console_sem);

  ignoring what's under drivers/staging/ (which is generally a bit of
a mess at the best of times), the above shows that there is almost
*no* usage of DEFINE_SEMAPHORE(), which surprised me somewhat, but i
can imagine a couple reasons.

  first, a lot of semaphores have been replaced by the newer and
simpler mutex.  also, rather than semaphores being created standalone,
they're normally defined as part of a structure, and when an instance
of that structure is declared, it's naturally initialized with
sema_init() in the appropriate initialization code.

  so i'm not surprised that the usage of DEFINE_SEMAPHORE() is
dropping, i'm just surprised that it's almost non-existent.  thoughts?



Robert P. J. Day                                 Ottawa, Ontario, CANADA

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday

More information about the Kernelnewbies mailing list