I think this is still not right, but when it comes to barriers we
need a true expert (Paul cc-ed).
this code roughly does (the only reader does unlock)
READER WRITER
readers = 0; state = 1;
wmb(); wmb();
CHECK(state != 0) CHECK(readers == 0)
We need to ensure that we can't miss both CHECKs. Either reader
should see RW_MUTEX_READER_SLOW, o writer sees "readers == 0"
and does not sleep.
In that case both barriers should be converted to smp_mb(). There
was a _long_ discussion about STORE-MB-LOAD behaviour, and experts
seem to believe everething is ok.
Another question. Isn't it possible to kill rw_mutex->status ?
I have a vague feeling you can change the code so that
rw_mutex_reader_slow() <=> "->waiter != NULL"
, but I am not sure.
Oleg.
-