diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2022-11-13 20:04:21 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2022-11-13 20:07:22 -0500 |
commit | c1e4d447f6dd0ee60495b651436d2055db7777ed (patch) | |
tree | 36a657f7018cecc6bad43e0e178ef1913154eba0 /libbcachefs/two_state_shared_lock.h | |
parent | 980f7437e2588d100456640cb863908a3cc6fc77 (diff) |
Update bcachefs sources to 8d3fc97ca3 bcachefs: Fixes for building in userspace
Diffstat (limited to 'libbcachefs/two_state_shared_lock.h')
-rw-r--r-- | libbcachefs/two_state_shared_lock.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libbcachefs/two_state_shared_lock.h b/libbcachefs/two_state_shared_lock.h new file mode 100644 index 00000000..1b4f1089 --- /dev/null +++ b/libbcachefs/two_state_shared_lock.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _BCACHEFS_TWO_STATE_LOCK_H +#define _BCACHEFS_TWO_STATE_LOCK_H + +#include <linux/atomic.h> +#include <linux/sched.h> +#include <linux/wait.h> + +/* + * Two-state lock - can be taken for add or block - both states are shared, + * like read side of rwsem, but conflict with other state: + */ +typedef struct { + atomic_long_t v; + wait_queue_head_t wait; +} two_state_lock_t; + +static inline void two_state_lock_init(two_state_lock_t *lock) +{ + atomic_long_set(&lock->v, 0); + init_waitqueue_head(&lock->wait); +} + +void bch2_two_state_unlock(two_state_lock_t *, int); +bool bch2_two_state_trylock(two_state_lock_t *, int); +void bch2_two_state_lock(two_state_lock_t *, int); + +#endif /* _BCACHEFS_TWO_STATE_LOCK_H */ |