Date: Fri, 14 Jul 2017 07:42:57 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r320981 - stable/11/sys/sys Message-ID: <201707140742.v6E7gvOP040850@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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__ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201707140742.v6E7gvOP040850>