Skip to content

Commit

Permalink
x86: micro-optimize __raw_read_trylock()
Browse files Browse the repository at this point in the history
The current version of __raw_read_trylock starts with decrementing the lock
and read its new value as a separate operation after that.

That makes 3 dereferences (read, write (after sub), read) whereas
a single atomic_dec_return does only two pointers dereferences (read, write).

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Frederic Weisbecker authored and Ingo Molnar committed Jan 26, 2009
1 parent 7106a5a commit 2d4d57d
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions arch/x86/include/asm/spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ static inline int __raw_read_trylock(raw_rwlock_t *lock)
{
atomic_t *count = (atomic_t *)lock;

atomic_dec(count);
if (atomic_read(count) >= 0)
if (atomic_dec_return(count) >= 0)
return 1;
atomic_inc(count);
return 0;
Expand Down

0 comments on commit 2d4d57d

Please sign in to comment.