1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_TWO_STATE_LOCK_H
3 #define _BCACHEFS_TWO_STATE_LOCK_H
5 #include <linux/atomic.h>
6 #include <linux/sched.h>
7 #include <linux/wait.h>
10 * Two-state lock - can be taken for add or block - both states are shared,
11 * like read side of rwsem, but conflict with other state:
15 wait_queue_head_t wait;
18 static inline void two_state_lock_init(two_state_lock_t *lock)
20 atomic_long_set(&lock->v, 0);
21 init_waitqueue_head(&lock->wait);
24 void bch2_two_state_unlock(two_state_lock_t *, int);
25 bool bch2_two_state_trylock(two_state_lock_t *, int);
26 void bch2_two_state_lock(two_state_lock_t *, int);
28 #endif /* _BCACHEFS_TWO_STATE_LOCK_H */