From: Peter Zijlstra <peterz@infradead.org>
To: lkml <linux-kernel@vger.kernel.org>
Cc: David Howells <dhowells@redhat.com>,
Matthew Wilcox <matthew@wil.cx>, Ingo Molnar <mingo@elte.hu>,
Nick Piggin <nickpiggin@yahoo.com.au>,
Christoph Hellwig <hch@infradead.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [RFC][PATCH] rwsem: rwsem_is_{read,write}_locked
Date: Wed, 25 Feb 2009 00:21:28 +0100 [thread overview]
Message-ID: <1235517688.18955.7.camel@twins> (raw)
In-Reply-To: <1235512716.4645.2397.camel@laptop>
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@chello.nl>
> ---
> +++ 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.
prev parent reply other threads:[~2009-02-24 23:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-24 21:58 [RFC][PATCH] rwsem: rwsem_is_{read,write}_locked Peter Zijlstra
2009-02-24 23:21 ` Peter Zijlstra [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1235517688.18955.7.camel@twins \
--to=peterz@infradead.org \
--cc=dhowells@redhat.com \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matthew@wil.cx \
--cc=mingo@elte.hu \
--cc=nickpiggin@yahoo.com.au \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox