From owner-dev-commits-src-main@freebsd.org Thu Dec 31 21:03:39 2020 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 65D9F4CFBA6; Thu, 31 Dec 2020 21:03:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D6LGz2PQKz3rJl; Thu, 31 Dec 2020 21:03:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 45DEE17149; Thu, 31 Dec 2020 21:03:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 0BVL3dZ4073826; Thu, 31 Dec 2020 21:03:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 0BVL3dP0073825; Thu, 31 Dec 2020 21:03:39 GMT (envelope-from git) Date: Thu, 31 Dec 2020 21:03:39 GMT Message-Id: <202012312103.0BVL3dP0073825@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ryan Libby Subject: git: ae4a8e52072a - main - bitset: implement BIT_TEST_CLR_ATOMIC & BIT_TEST_SET_ATOMIC MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rlibby X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ae4a8e52072a87bfd49d553b9b14450c626269f8 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Dec 2020 21:03:39 -0000 The branch main has been updated by rlibby: URL: https://cgit.FreeBSD.org/src/commit/?id=ae4a8e52072a87bfd49d553b9b14450c626269f8 commit ae4a8e52072a87bfd49d553b9b14450c626269f8 Author: Ryan Libby AuthorDate: 2020-12-31 21:02:45 +0000 Commit: Ryan Libby CommitDate: 2020-12-31 21:02:45 +0000 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 --- share/man/man9/bitset.9 | 14 +++++++++++++- sys/sys/bitset.h | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/share/man/man9/bitset.9 b/share/man/man9/bitset.9 index d597282fea9a..1e080f515788 100644 --- a/share/man/man9/bitset.9 +++ b/share/man/man9/bitset.9 @@ -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 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; \