svn commit: r320981 - stable/11/sys/sys
Konstantin Belousov
kib at FreeBSD.org
Fri Jul 14 07:42:59 UTC 2017
Author: kib
Date: Fri Jul 14 07:42:57 2017
New Revision: 320981
URL: https://svnweb.freebsd.org/changeset/base/320981
Log:
MFC r320501:
Correct fences for sys/refcount.h.
Modified:
stable/11/sys/sys/refcount.h
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/sys/sys/refcount.h
==============================================================================
--- stable/11/sys/sys/refcount.h Fri Jul 14 02:15:48 2017 (r320980)
+++ stable/11/sys/sys/refcount.h Fri Jul 14 07:42:57 2017 (r320981)
@@ -50,7 +50,7 @@ refcount_acquire(volatile u_int *count)
{
KASSERT(*count < UINT_MAX, ("refcount %p overflowed", count));
- atomic_add_acq_int(count, 1);
+ atomic_add_int(count, 1);
}
static __inline int
@@ -58,10 +58,20 @@ refcount_release(volatile u_int *count)
{
u_int old;
- /* XXX: Should this have a rel membar? */
+ atomic_thread_fence_rel();
old = atomic_fetchadd_int(count, -1);
KASSERT(old > 0, ("negative refcount %p", count));
- return (old == 1);
+ if (old > 1)
+ return (0);
+
+ /*
+ * 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.
+ */
+ atomic_thread_fence_acq();
+ return (1);
}
#endif /* ! __SYS_REFCOUNT_H__ */
More information about the svn-src-all
mailing list