On Wed, Jan 04, 2017 at 02:26:17PM +0100, Paolo Bonzini wrote: > +/* Decrement a counter, and return locked if it is decremented to zero. > + * It is impossible for the counter to become nonzero while the mutex > + * is taken. > + */ > +bool qemu_lockcnt_dec_and_lock(QemuLockCnt *lockcnt) > +{ > + int val = atomic_read(&lockcnt->count);
I think I've figured out the answer to my question why this isn't an atomic_mb_read(): The following accesses use atomic_cmpxchg() or atomic_fetch_dec(). There is no adverse effect if we read an outdated value here since the cmpxchg/fetch_dec are sequentially consistent and explicitly require us to handle the old value. > + while (val > 1) { > + int old = atomic_cmpxchg(&lockcnt->count, val, val - 1); > + if (old != val) { > + val = old; > + continue; > + } > + > + return false; > + } > + > + qemu_lockcnt_lock(lockcnt); > + if (atomic_fetch_dec(&lockcnt->count) == 1) { > + return true; > + } > + > + qemu_lockcnt_unlock(lockcnt); > + return false;
signature.asc
Description: PGP signature