Re: [Patch RFC 01/37] semaphore: Add DEFINE_SEMAPHORE,semaphore_init, semaphore_init_locked

From: Christoph Hellwig
Date: Mon Jul 27 2009 - 11:24:17 EST


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.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/