Re: [PATCH RFC] 'spinlock/rwlock fixes' V3 [1/1]
From: Linus Torvalds
Date: Thu Jan 20 2005 - 12:40:00 EST
On Thu, 20 Jan 2005, Ingo Molnar wrote:
>
> right. Replace patch #4 with:
>
> /**
> * read_can_lock - would read_trylock() succeed?
> * @lock: the rwlock in question.
> */
> -#define read_can_lock(x) (atomic_read((atomic_t *)&(x)->lock) > 0)
> +static inline int read_can_lock(rwlock_t *rw)
> +{
> + return rw->lock > 0;
> +}
No, it does need the cast to signed, otherwise it will return true for the
case where somebody holds the write-lock _and_ there's a pending reader
waiting too (the write-lock will make it zero, the pending reader will
wrap around and make it negative, but since "lock" is "unsigned", it will
look like a large value to "read_can_lock".
I also think I'd prefer to do the things as macros, and do the type-safety
by just renaming the "lock" field like Chris did. We had an issue with gcc
being very slow recently, and that was due to some inline functions in
header files: gcc does a lot of work on an inline function regardless of
whether it is used or not, and the spinlock header file is included pretty
much _everywhere_...
Clearly inline functions are "nicer", but they do come with a cost.
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/