Skip to content

Commit 28ce0e7

Browse files
Waiman-LongPeter Zijlstra
authored andcommitted
locking/qrwlock: Cleanup queued_write_lock_slowpath()
Make the code more readable by replacing the atomic_cmpxchg_acquire() by an equivalent atomic_try_cmpxchg_acquire() and change atomic_add() to atomic_or(). For architectures that use qrwlock, I do not find one that has an atomic_add() defined but not an atomic_or(). I guess it should be fine by changing atomic_add() to atomic_or(). Note that the previous use of atomic_add() isn't wrong as only one writer that is the wait_lock owner can set the waiting flag and the flag will be cleared later on when acquiring the write lock. Suggested-by: Linus Torvalds <[email protected]> Signed-off-by: Waiman Long <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Will Deacon <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 1139aeb commit 28ce0e7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

kernel/locking/qrwlock.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ void queued_write_lock_slowpath(struct qrwlock *lock)
6666
arch_spin_lock(&lock->wait_lock);
6767

6868
/* Try to acquire the lock directly if no reader is present */
69-
if (!atomic_read(&lock->cnts) &&
70-
(atomic_cmpxchg_acquire(&lock->cnts, 0, _QW_LOCKED) == 0))
69+
if (!(cnts = atomic_read(&lock->cnts)) &&
70+
atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED))
7171
goto unlock;
7272

7373
/* Set the waiting flag to notify readers that a writer is pending */
74-
atomic_add(_QW_WAITING, &lock->cnts);
74+
atomic_or(_QW_WAITING, &lock->cnts);
7575

7676
/* When no more readers or writers, set the locked flag */
7777
do {

0 commit comments

Comments
 (0)