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
This commit is contained in:
Ryan Libby 2020-12-31 13:02:45 -08:00
parent 1e54857bd9
commit ae4a8e5207
2 changed files with 27 additions and 1 deletions

View File

@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd August 25, 2020
.Dd December 31, 2020
.Dt BITSET 9
.Os
.Sh NAME
@ -60,6 +60,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
@ -137,6 +139,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"
@ -205,6 +211,9 @@ in the bitset pointed to by
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 whether it was set.
.Pp
The
.Fn BIT_COPY
@ -236,6 +245,9 @@ macro is identical, but the bit is set atomically.
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 whether it was set.
.Pp
The
.Fn BIT_ZERO

View File

@ -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; \