Date: Tue, 27 Oct 2020 18:11:11 +0000 (UTC) From: Mateusz Guzik <mjg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367088 - head/sys/sys Message-ID: <202010271811.09RIBBqZ039125@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mjg Date: Tue Oct 27 18:11:11 2020 New Revision: 367088 URL: https://svnweb.freebsd.org/changeset/base/367088 Log: refcount: make it atomic-clean While here consistently use 'old' in all places. Tested by: pho Modified: head/sys/sys/refcount.h Modified: head/sys/sys/refcount.h ============================================================================== --- head/sys/sys/refcount.h Tue Oct 27 18:08:33 2020 (r367087) +++ head/sys/sys/refcount.h Tue Oct 27 18:11:11 2020 (r367088) @@ -63,7 +63,7 @@ refcount_init(volatile u_int *count, u_int value) { KASSERT(!REFCOUNT_SATURATED(value), ("invalid initial refcount value %u", value)); - *count = value; + atomic_store_int(count, value); } static __inline u_int @@ -95,13 +95,14 @@ refcount_acquiren(volatile u_int *count, u_int n) static __inline __result_use_check bool refcount_acquire_checked(volatile u_int *count) { - u_int lcount; + u_int old; - for (lcount = *count;;) { - if (__predict_false(REFCOUNT_SATURATED(lcount + 1))) + old = atomic_load_int(count); + for (;;) { + if (__predict_false(REFCOUNT_SATURATED(old + 1))) return (false); - if (__predict_true(atomic_fcmpset_int(count, &lcount, - lcount + 1) == 1)) + if (__predict_true(atomic_fcmpset_int(count, &old, + old + 1) == 1)) return (true); } } @@ -115,7 +116,7 @@ refcount_acquire_if_gt(volatile u_int *count, u_int n) { u_int old; - old = *count; + old = atomic_load_int(count); for (;;) { if (old <= n) return (false); @@ -174,7 +175,7 @@ refcount_release_if_gt(volatile u_int *count, u_int n) KASSERT(n > 0, ("refcount_release_if_gt: Use refcount_release for final ref")); - old = *count; + old = atomic_load_int(count); for (;;) { if (old <= n) return (false);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202010271811.09RIBBqZ039125>