Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Jul 2021 12:48:56 GMT
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 2f6dd4a29198 - stable/12 - refcount: add refcount_releasen
Message-ID:  <202107051248.165CmuV7012044@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=2f6dd4a29198ab82ab013e15b4eb2fa6de25d5bf

commit 2f6dd4a29198ab82ab013e15b4eb2fa6de25d5bf
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2021-07-05 12:45:32 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2021-07-05 12:48:23 +0000

    refcount: add refcount_releasen
    
    This is a direct commit as the routine in main was added as a side
    effect of functionality which later got reverted.
---
 sys/sys/refcount.h | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/sys/sys/refcount.h b/sys/sys/refcount.h
index 44edbdf953a0..19a8f38772a0 100644
--- a/sys/sys/refcount.h
+++ b/sys/sys/refcount.h
@@ -70,26 +70,33 @@ refcount_acquire_checked(volatile u_int *count)
 }
 
 static __inline bool
-refcount_release(volatile u_int *count)
+refcount_releasen(volatile u_int *count, u_int n)
 {
 	u_int old;
 
 	atomic_thread_fence_rel();
-	old = atomic_fetchadd_int(count, -1);
+	old = atomic_fetchadd_int(count, -n);
 	KASSERT(old > 0, ("refcount %p is zero", count));
-	if (old > 1)
+	if (old > n)
 		return (false);
 
 	/*
 	 * Last reference.  Signal the user to call the destructor.
 	 *
-	 * Ensure that the destructor sees all updates.  The fence_rel
-	 * at the start of the function synchronized with this fence.
+	 * Ensure that the destructor sees all updates. This synchronizes with
+	 * release fences from all routines which drop the count.
 	 */
 	atomic_thread_fence_acq();
 	return (true);
 }
 
+static __inline bool
+refcount_release(volatile u_int *count)
+{
+
+        return (refcount_releasen(count, 1));
+}
+
 /*
  * This functions returns non-zero if the refcount was
  * incremented. Else zero is returned.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202107051248.165CmuV7012044>