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 committed by Sebastian Huber
parent 9d50b44689
commit fb0a5865e4
1 changed files with 14 additions and 0 deletions

View File

@ -176,6 +176,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))
@ -188,6 +194,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; \