Re: [PATCH 3/4] locking/rwbase: Fix rwbase_write_lock() vs __rwbase_read_lock()

From: Thomas Gleixner
Date: Tue Sep 14 2021 - 03:46:06 EST


On Thu, Sep 09 2021 at 12:59, Peter Zijlstra wrote:

> Boqun noticed that the write-trylock sequence of load+set is broken in
> rwbase_write_lock()'s wait-loop since they're not both under the same
> wait_lock instance.

Confused.

lock(); A

for (; atomic_read(readers);) {
...
unlock();
..
lock(); B
}

atomic_set();
unlock(); A or B

The read/set is always in the same lock instance.

> Restructure the code to make this more obvious and correct.

I agree that it's easier to read, but I disagree that it makes the code
more correct.

Thanks,

tglx