Subject: Re: semaphore
To: Simon J. Gerraty <sjg@crufty.net>
From: Darren Reed <darrenr@reed.wattle.id.au>
List: tech-kern
Date: 03/22/2002 21:18:37
In some email I received from Simon J. Gerraty, sie wrote:
> > I thought one purpose of the newlock branch was (among other things)
> > about improving the API to our locking primitives.  At least for folks
> > who don't speak dutch, semaphores typically have a *HORRID* API.
> > Which operation is "p" and which one is "v" again?
> 
> Yep, so my implementation provides:
> 
> void	sema_init(sema_t *sp, int cnt, const char *wmesg, int flags);
> void	sema_clear(sema_t *sp);		/* shutdown */
> void	sema_setflags(sema_t *sp, int flags);
> int	sema_signal(sema_t *sp);	/* V() */
> int	sema_signal_n(sema_t *sp, int n); /* V() * n */
> void	sema_spinwait(sema_t *sp, int n); /* spin version of P() * n */
> void	sema_wait(sema_t *sp);		/* sleep version of P() */
> void	sema_wait_n(sema_t *sp, int n);	/* sleep version of P() * n */
> 
> #define sema_signal(sp) sema_signal_n((sp), 1)

How about adding:

#define	sema_v(x)	sema_signal(x)
#define	sema_p(x)	sema_spinwait(x)
#define	sema_p_wait(x)	sema_wait(x)

just to make it easier...

I'm not sure I understand the "n" mutation here...

Darren