| Date | Mon, 27 Jul 2009 11:24:08 -0400 | From | Christoph Hellwig <> | Subject | Re: [Patch RFC 01/37] semaphore: Add DEFINE_SEMAPHORE, semaphore_init, semaphore_init_locked |
| |
On Sun, Jul 26, 2009 at 08:17:11AM -0000, Thomas Gleixner wrote: > The full cleanup of init_MUTEX[_LOCKED] and DECLARE_MUTEX has not been > done. Some of the users are real semaphores and we should name them as > such instead of confusing everyone with "MUTEX".
> +#define DEFINE_SEMAPHORE(name) \ > + struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1) > +
> +static inline void semaphore_init(struct semanphore *sem) > +{ > + sema_init(sem, 1); > +} > + > +/* > + * semaphore_init_locked() is mostly a sign for a mutex which is > + * abused as completion. > + */ > +static inline void __deprecated semaphore_init_locked(struct semanphore *sem) > +{ > + sema_init(sem, 0); > +}
The CS literature doesn't really know about a default value for counting semaphores. I think you're better off converting init_MUTEX and init_MUTEX_locked to explicit sema_init use than adding these and introducing another semaphore_* namespace in addition to the sema_* we already have. Adding a DEFINE_SEMAPHORE makes sense, but it should take a second argument for it's initial value.
|