]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Make isc_refcount_current() atomically read the counter value (#46074)
authorMukund Sivaraman <muks@isc.org>
Wed, 27 Sep 2017 09:38:06 +0000 (15:08 +0530)
committerMukund Sivaraman <muks@isc.org>
Wed, 27 Sep 2017 09:39:04 +0000 (15:09 +0530)
CHANGES
lib/isc/include/isc/refcount.h

diff --git a/CHANGES b/CHANGES
index 5cb3e7252bba9dbe50f3110194f4b9a6f20df48b..801c656160227326bf1c51007c33ee070574316b 100644 (file)
--- 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]
index acc99599620b3b03b55c9f6bf1a4dbd655c131ba..24ad9dae945ba7b00ccc3de76c2d3c8087a0b3f7 100644 (file)
@@ -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);      \