From: Mukund Sivaraman Date: Wed, 27 Sep 2017 09:38:06 +0000 (+0530) Subject: Make isc_refcount_current() atomically read the counter value (#46074) X-Git-Tag: v9.12.0b1~132 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=abb8813a3338ee63d28aa14b7dde74892fe1879f;p=thirdparty%2Fbind9.git Make isc_refcount_current() atomically read the counter value (#46074) --- diff --git a/CHANGES b/CHANGES index 5cb3e7252bb..801c6561602 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +4741. [bug] Make isc_refcount_current() atomically read the + counter value. [RT #46074] + 4740. [cleanup] Avoid triggering format-truncated warnings. [RT #46107] 4739. [cleanup] Address clang static analysis warnings. [RT #45952] diff --git a/lib/isc/include/isc/refcount.h b/lib/isc/include/isc/refcount.h index acc99599620..24ad9dae945 100644 --- a/lib/isc/include/isc/refcount.h +++ b/lib/isc/include/isc/refcount.h @@ -104,11 +104,13 @@ typedef struct isc_refcount { #endif } isc_refcount_t; -#define isc_refcount_destroy(rp) REQUIRE((rp)->refs == 0) -#define isc_refcount_current(rp) ((unsigned int)((rp)->refs)) - #if defined(ISC_REFCOUNT_HAVESTDATOMIC) +#define isc_refcount_current(rp) \ + ((unsigned int)(atomic_load_explicit(&(rp)->refs, \ + memory_order_relaxed))) +#define isc_refcount_destroy(rp) REQUIRE(isc_refcount_current(rp) == 0) + #define isc_refcount_increment0(rp, tp) \ do { \ unsigned int *_tmp = (unsigned int *)(tp); \ @@ -143,6 +145,10 @@ typedef struct isc_refcount { #else /* ISC_REFCOUNT_HAVESTDATOMIC */ +#define isc_refcount_current(rp) \ + ((unsigned int)(isc_atomic_xadd(&(rp)->refs, 0))) +#define isc_refcount_destroy(rp) REQUIRE(isc_refcount_current(rp) == 0) + #define isc_refcount_increment0(rp, tp) \ do { \ unsigned int *_tmp = (unsigned int *)(tp); \