/* * Two-state lock - can be taken for add or block - both states are shared, * like read side of rwsem, but conflict with other state:
*/ typedefstruct {
atomic_long_t v;
wait_queue_head_t wait;
} two_state_lock_t;
staticinlinevoid bch2_two_state_unlock(two_state_lock_t *lock, int s)
{ long i = s ? 1 : -1;
EBUG_ON(atomic_long_read(&lock->v) == 0);
if (atomic_long_sub_return_release(i, &lock->v) == 0)
wake_up_all(&lock->wait);
}
staticinlinebool bch2_two_state_trylock(two_state_lock_t *lock, int s)
{ long i = s ? 1 : -1; long old;
old = atomic_long_read(&lock->v); do { if (i > 0 ? old < 0 : old > 0) returnfalse;
} while (!atomic_long_try_cmpxchg_acquire(&lock->v, &old, old + i));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.