Re: [RFC][PATCH] rwsem: rwsem_is_{read,write}_locked

From: Peter Zijlstra
Date: Tue Feb 24 2009 - 18:22:18 EST


On Tue, 2009-02-24 at 22:58 +0100, Peter Zijlstra wrote:
> Christoph requested an extended is_locked interface for rwsems. I think
> the below ought to do, then again, I might have missed something.
>
> Signed-off-by: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
> ---

> +++ b/include/linux/rwsem.h
> @@ -20,8 +20,24 @@ struct rw_semaphore;
> #include <linux/rwsem-spinlock.h> /* use a generic implementation */
> #else
> #include <asm/rwsem.h> /* use an arch-specific implementation */
> +
> +static inline int rwsem_is_locked(struct rw_semaphore *sem)
> +{
> + return (sem->count != 0);
> +}
> +
> +static inline int rwsem_is_write_locked(struct rw_semaphore *sem)
> +{
> + return (sem->count & RWSEM_ACTIVE_MASK) == RWSEM_ACTIVE_MASK;
> +}

OK, that's not right. Concurrent down_write() calls xadd
RWSEM_ACTIVE_WRITE_BIAS, which has a 1 in that mask, so we're going to
deviate an unspecified number.

That one will make it roll over into (count & MASK) >= 0 which is the
exact range readers use too, this might be a tad harder than hoped.

Will ponder in the morning.
--
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/