···2233#include "two_state_shared_lock.h"4455-void bch2_two_state_unlock(two_state_lock_t *lock, int s)55+void __bch2_two_state_lock(two_state_lock_t *lock, int s)66{77- long i = s ? 1 : -1;88-99- BUG_ON(atomic_long_read(&lock->v) == 0);1010-1111- if (atomic_long_sub_return_release(i, &lock->v) == 0)1212- wake_up_all(&lock->wait);1313-}1414-1515-bool bch2_two_state_trylock(two_state_lock_t *lock, int s)1616-{1717- long i = s ? 1 : -1;1818- long v = atomic_long_read(&lock->v), old;1919-2020- do {2121- old = v;2222-2323- if (i > 0 ? v < 0 : v > 0)2424- return false;2525- } while ((v = atomic_long_cmpxchg_acquire(&lock->v,2626- old, old + i)) != old);2727- return true;2828-}2929-3030-void bch2_two_state_lock(two_state_lock_t *lock, int s)3131-{3232- wait_event(lock->wait, bch2_two_state_trylock(lock, s));77+ __wait_event(lock->wait, bch2_two_state_trylock(lock, s));338}
+34-3
fs/bcachefs/two_state_shared_lock.h
···66#include <linux/sched.h>77#include <linux/wait.h>8899+#include "util.h"1010+911/*1012 * Two-state lock - can be taken for add or block - both states are shared,1113 * like read side of rwsem, but conflict with other state:···2321 init_waitqueue_head(&lock->wait);2422}25232626-void bch2_two_state_unlock(two_state_lock_t *, int);2727-bool bch2_two_state_trylock(two_state_lock_t *, int);2828-void bch2_two_state_lock(two_state_lock_t *, int);2424+static inline void bch2_two_state_unlock(two_state_lock_t *lock, int s)2525+{2626+ long i = s ? 1 : -1;2727+2828+ EBUG_ON(atomic_long_read(&lock->v) == 0);2929+3030+ if (atomic_long_sub_return_release(i, &lock->v) == 0)3131+ wake_up_all(&lock->wait);3232+}3333+3434+static inline bool bch2_two_state_trylock(two_state_lock_t *lock, int s)3535+{3636+ long i = s ? 1 : -1;3737+ long v = atomic_long_read(&lock->v), old;3838+3939+ do {4040+ old = v;4141+4242+ if (i > 0 ? v < 0 : v > 0)4343+ return false;4444+ } while ((v = atomic_long_cmpxchg_acquire(&lock->v,4545+ old, old + i)) != old);4646+ return true;4747+}4848+4949+void __bch2_two_state_lock(two_state_lock_t *, int);5050+5151+static inline void bch2_two_state_lock(two_state_lock_t *lock, int s)5252+{5353+ if (!bch2_two_state_trylock(lock, s))5454+ __bch2_two_state_lock(lock, s);5555+}29563057#endif /* _BCACHEFS_TWO_STATE_LOCK_H */