aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorRyan Libby <rlibby@FreeBSD.org>2020-12-31 21:02:45 +0000
committerRyan Libby <rlibby@FreeBSD.org>2020-12-31 21:02:45 +0000
commitae4a8e52072a87bfd49d553b9b14450c626269f8 (patch)
treebaf46a9e617360c2047603595802d8655bf2b7f8 /sys
parent1e54857bd9f5791ec1edfc5c21edb374519e9061 (diff)
downloadsrc-ae4a8e52072a87bfd49d553b9b14450c626269f8.tar.gz
src-ae4a8e52072a87bfd49d553b9b14450c626269f8.zip
bitset: implement BIT_TEST_CLR_ATOMIC & BIT_TEST_SET_ATOMIC
That is, provide wrappers around the atomic_testandclear and atomic_testandset primitives. Submitted by: jeff Reviewed by: cem, kib, markj Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D22702
Diffstat (limited to 'sys')
-rw-r--r--sys/sys/bitset.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/sys/sys/bitset.h b/sys/sys/bitset.h
index 97f18def7236..2b5df78a8193 100644
--- a/sys/sys/bitset.h
+++ b/sys/sys/bitset.h
@@ -173,6 +173,12 @@
(d)->__bits[__i] = (s1)->__bits[__i] ^ (s2)->__bits[__i];\
} while (0)
+/*
+ * Note, the atomic(9) API is not consistent between clear/set and
+ * testandclear/testandset in whether the value argument is a mask
+ * or a bit index.
+ */
+
#define BIT_CLR_ATOMIC(_s, n, p) \
atomic_clear_long(&(p)->__bits[__bitset_word(_s, n)], \
__bitset_mask((_s), n))
@@ -185,6 +191,14 @@
atomic_set_acq_long(&(p)->__bits[__bitset_word(_s, n)], \
__bitset_mask((_s), n))
+#define BIT_TEST_CLR_ATOMIC(_s, n, p) \
+ (atomic_testandclear_long( \
+ &(p)->__bits[__bitset_word((_s), (n))], (n)) != 0)
+
+#define BIT_TEST_SET_ATOMIC(_s, n, p) \
+ (atomic_testandset_long( \
+ &(p)->__bits[__bitset_word((_s), (n))], (n)) != 0)
+
/* Convenience functions catering special cases. */
#define BIT_AND_ATOMIC(_s, d, s) do { \
__size_t __i; \