Subject: Re: Kernel semaphore API
To: Andrew Doran <>
From: Simon J. Gerraty <>
List: tech-kern
Date: 10/01/2007 14:13:11
>Here's an API for counting semaphores in the kernel. It's similar to what we
>have now for condition variables.

>Any comments?

Looks a bit like the API I did back in 2001, which I think Jason
sucked into the newlock branch - but may have fallen out.

void sema_init (sema_t *sp, int cnt, const char *wmesg, int flags)
void sema_clear (sema_t *sp)
void sema_setflags (sema_t *sp, int flags)
void sema_wait (sema_t *sp)
void sema_wait_n (sema_t *sp, int n)
void sema_spinwait (sema_t *sp, int n)
int sema_signal_n (sema_t *sp, int n)

sema_signal is just sema_signal_n with n=1

sema_signal_n and sema_wait_n allow opertating on N of some resource 
at a time.

I agree that the P() and V() names are poor ;-)
[I doubt my implementation is bug free - I was playing with it while
trying to get MP working on Hypersparc]