summaryrefslogtreecommitdiff
path: root/fs/bcachefs/six.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-05-20 20:40:08 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-08-14 12:28:32 -0400
commit019c03e351898cb82758d6fefafd775f43549808 (patch)
tree003a726ab405bde5602d2ce8e905944dd801840e /fs/bcachefs/six.c
parentf6ed17b0ed2c8f29794c382d86b2f550a722d59a (diff)
six locks: six_lock_readers_add()
This moves a helper out of the bcachefs code that shouldn't have been there, since it touches six lock internals. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/six.c')
-rw-r--r--fs/bcachefs/six.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/fs/bcachefs/six.c b/fs/bcachefs/six.c
index 728761530ad9..2728a2784553 100644
--- a/fs/bcachefs/six.c
+++ b/fs/bcachefs/six.c
@@ -40,6 +40,8 @@ struct six_lock_vals {
enum six_lock_type unlock_wakeup;
};
+#define __SIX_VAL(field, _v) (((union six_lock_state) { .field = _v }).v)
+
#define __SIX_LOCK_HELD_read __SIX_VAL(read_lock, ~0)
#define __SIX_LOCK_HELD_intent __SIX_VAL(intent_lock, ~0)
#define __SIX_LOCK_HELD_write __SIX_VAL(seq, 1)
@@ -847,3 +849,14 @@ struct six_lock_count six_lock_counts(struct six_lock *lock)
return ret;
}
EXPORT_SYMBOL_GPL(six_lock_counts);
+
+void six_lock_readers_add(struct six_lock *lock, int nr)
+{
+ if (lock->readers)
+ this_cpu_add(*lock->readers, nr);
+ else if (nr > 0)
+ atomic64_add(__SIX_VAL(read_lock, nr), &lock->state.counter);
+ else
+ atomic64_sub(__SIX_VAL(read_lock, -nr), &lock->state.counter);
+}
+EXPORT_SYMBOL_GPL(six_lock_readers_add);