Re: [PATCH RFC] 'spinlock/rwlock fixes' V3 [1/1]

From: Linus Torvalds
Date: Thu Jan 20 2005 - 10:59:22 EST




On Thu, 20 Jan 2005, Peter Chubb wrote:
>
> I suggest reversing the sense of the macros, and having read_can_lock()
> and write_can_lock()
>
> Meaning:
> read_can_lock() --- a read_lock() would have succeeded
> write_can_lock() --- a write_lock() would have succeeded.

Yes. This has the advantage of being readable, and the "sense" of the test
always being obvious.

We have a sense problem with the "trylock()" cases - some return "it was
locked" (semaphores), and some return "I succeeded" (spinlocks), so not
only is the sense not immediately obvious from the usage, it's actually
_different_ for semaphores and for spinlocks.

So I like "read_can_lock()", since it's also obvious what it returns.

(And yes, we should fix the semaphore trylock return code, dammit.)

Linus
-
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/