Page MenuHomeFreeBSD

D22702.id65303.diff
No OneTemporary

D22702.id65303.diff

Index: share/man/man9/bitset.9
===================================================================
--- share/man/man9/bitset.9
+++ share/man/man9/bitset.9
@@ -59,6 +59,8 @@
.Nm BIT_CLR_ATOMIC ,
.Nm BIT_SET_ATOMIC ,
.Nm BIT_SET_ATOMIC_ACQ ,
+.Nm BIT_TEST_SET_ATOMIC ,
+.Nm BIT_TEST_CLR_ATOMIC ,
.Nm BIT_AND_ATOMIC ,
.Nm BIT_OR_ATOMIC ,
.Nm BIT_COPY_STORE_REL
@@ -134,6 +136,10 @@
.Fn BIT_CLR_ATOMIC "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
.Fn BIT_SET_ATOMIC "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
.Fn BIT_SET_ATOMIC_ACQ "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
+.Ft bool
+.Fn BIT_TEST_SET_ATOMIC "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
+.Ft bool
+.Fn BIT_TEST_CLR_ATOMIC "const SETSIZE" "size_t bit" "struct STRUCTNAME *bitset"
.\"
.Fo BIT_AND_ATOMIC
.Fa "const SETSIZE" "struct STRUCTNAME *dst" "struct STRUCTNAME *src"
@@ -202,6 +208,9 @@
The
.Fn BIT_CLR_ATOMIC
macro is identical, but the bit is cleared atomically.
+The
+.Fn BIT_TEST_CLR_ATOMIC
+macro atomically clears the bit and returns its previous value.
.Pp
The
.Fn BIT_COPY
@@ -233,6 +242,9 @@
The
.Fn BIT_SET_ATOMIC_ACQ
macro sets the bit with acquire semantics.
+The
+.Fn BIT_TEST_SET_ATOMIC
+macro atomically sets the bit and returns its previous value.
.Pp
The
.Fn BIT_ZERO
Index: sys/sys/bitset.h
===================================================================
--- sys/sys/bitset.h
+++ sys/sys/bitset.h
@@ -185,6 +185,21 @@
atomic_set_acq_long(&(p)->__bits[__bitset_word(_s, n)], \
__bitset_mask((_s), n))
+/*
+ * Note, the atomic_testandclear and atomic_testandset APIs are defined
+ * as taking the bit number, and not a mask, to select. They are also
+ * defined to take a modulus by the type size, so we don't bother with
+ * the modulus ourselves.
+ */
+
+#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; \

File Metadata

Mime Type
text/plain
Expires
Fri, May 2, 8:31 AM (17 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17902452
Default Alt Text
D22702.id65303.diff (2 KB)

Event Timeline