]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Unwrap isc_refcount_t from struct isc_refcount as it is always a simple type now
authorOndřej Surý <ondrej@sury.org>
Sat, 17 Mar 2018 19:59:19 +0000 (19:59 +0000)
committerOndřej Surý <ondrej@sury.org>
Thu, 24 May 2018 08:37:06 +0000 (10:37 +0200)
lib/isc/Makefile.in
lib/isc/include/isc/refcount.h
lib/isc/refcount.c [deleted file]

index 9c1465fe78c697d40edb8f8e0960a52b7993063f..68cf71c0533933906de7157fc93061f18038bb1f 100644 (file)
@@ -57,7 +57,7 @@ OBJS =                @ISC_EXTRA_OBJS@ @ISC_PK11_O@ @ISC_PK11_RESULT_O@ \
                md5.@O@ mem.@O@ mutexblock.@O@ \
                netaddr.@O@ netscope.@O@ pool.@O@ \
                parseint.@O@ portset.@O@ quota.@O@ radix.@O@ random.@O@ \
-               ratelimiter.@O@ refcount.@O@ region.@O@ regex.@O@ result.@O@ \
+               ratelimiter.@O@ region.@O@ regex.@O@ result.@O@ \
                rwlock.@O@ \
                safe.@O@ serial.@O@ sha1.@O@ sha2.@O@ sockaddr.@O@ stats.@O@ \
                string.@O@ strtoul.@O@ symtab.@O@ task.@O@ taskpool.@O@ \
@@ -75,7 +75,7 @@ SRCS =                @ISC_EXTRA_SRCS@ @ISC_PK11_C@ @ISC_PK11_RESULT_C@ \
                md5.c mem.c mutexblock.c \
                netaddr.c netscope.c pool.c \
                parseint.c portset.c quota.c radix.c random.c \
-               ratelimiter.c refcount.c region.c regex.c result.c rwlock.c \
+               ratelimiter.c region.c regex.c result.c rwlock.c \
                safe.c serial.c sha1.c sha2.c sockaddr.c stats.c string.c \
                strtoul.c symtab.c task.c taskpool.c timer.c \
                tm.c version.c
index e0df1c82aea65f6f9d7bc8321b213e6f12510d58..4ff05c916456e10ee44a156c3cb20abf5c6ba106 100644 (file)
@@ -91,42 +91,40 @@ ISC_LANG_BEGINDECLS
  */
 #ifdef ISC_PLATFORM_USETHREADS
 
-typedef struct isc_refcount {
-       atomic_int_fast32_t refs;
-} isc_refcount_t;
+typedef atomic_int_fast32_t isc_refcount_t;
 
-#define isc_refcount_current(rp)                                       \
-       ((unsigned int)(atomic_load_explicit(&(rp)->refs,               \
+#define isc_refcount_current(ref)                                      \
+       ((unsigned int)(atomic_load_explicit(ref,                       \
                                             memory_order_relaxed)))
-#define isc_refcount_destroy(rp) ISC_REQUIRE(isc_refcount_current(rp) == 0)
+#define isc_refcount_destroy(ref) ISC_REQUIRE(isc_refcount_current(ref) == 0)
 
-#define isc_refcount_increment0(rp, tp)                                \
+#define isc_refcount_increment0(ref, tp)                               \
        do {                                                    \
                unsigned int *_tmp = (unsigned int *)(tp);      \
                isc_int32_t prev;                               \
                prev = atomic_fetch_add_explicit                \
-                       (&(rp)->refs, 1, memory_order_relaxed); \
+                       (ref, 1, memory_order_relaxed);                 \
                if (_tmp != NULL)                               \
                        *_tmp = prev + 1;                       \
        } while (0)
 
-#define isc_refcount_increment(rp, tp)                         \
+#define isc_refcount_increment(ref, tp)                                \
        do {                                                    \
                unsigned int *_tmp = (unsigned int *)(tp);      \
                isc_int32_t prev;                               \
                prev = atomic_fetch_add_explicit                \
-                       (&(rp)->refs, 1, memory_order_relaxed); \
+                       (ref, 1, memory_order_relaxed);                 \
                ISC_REQUIRE(prev > 0);                          \
                if (_tmp != NULL)                               \
                        *_tmp = prev + 1;                       \
        } while (0)
 
-#define isc_refcount_decrement(rp, tp)                         \
+#define isc_refcount_decrement(ref, tp)                                \
        do {                                                    \
                unsigned int *_tmp = (unsigned int *)(tp);      \
                isc_int32_t prev;                               \
                prev = atomic_fetch_sub_explicit                \
-                       (&(rp)->refs, 1, memory_order_relaxed); \
+                       (ref, 1, memory_order_relaxed);         \
                ISC_REQUIRE(prev > 0);                          \
                if (_tmp != NULL)                               \
                        *_tmp = prev - 1;                       \
@@ -138,41 +136,46 @@ typedef struct isc_refcount {
        int refs;
 } isc_refcount_t;
 
-#define isc_refcount_destroy(rp) ISC_REQUIRE((rp)->refs == 0)
-#define isc_refcount_current(rp) ((unsigned int)((rp)->refs))
+#define isc_refcount_destroy(ref) ISC_REQUIRE(ref == 0)
+#define isc_refcount_current(ref) ((unsigned int)(ref)
 
-#define isc_refcount_increment0(rp, tp)                                        \
+#define isc_refcount_increment0(ref, tp)                                       \
        do {                                                            \
                unsigned int *_tmp = (unsigned int *)(tp);              \
-               int _n = ++(rp)->refs;                                  \
+               int _n = ++ref;                                         \
                if (_tmp != NULL)                                       \
                        *_tmp = _n;                                     \
        } while (0)
 
-#define isc_refcount_increment(rp, tp)                                 \
+#define isc_refcount_increment(ref, tp)                                        \
        do {                                                            \
                unsigned int *_tmp = (unsigned int *)(tp);              \
                int _n;                                                 \
-               ISC_REQUIRE((rp)->refs > 0);                            \
-               _n = ++(rp)->refs;                                      \
+               ISC_REQUIRE(ref > 0);                                   \
+               _n = ++ref;                                             \
                if (_tmp != NULL)                                       \
                        *_tmp = _n;                                     \
        } while (0)
 
-#define isc_refcount_decrement(rp, tp)                                 \
+#define isc_refcount_decrement(ref, tp)                                        \
        do {                                                            \
                unsigned int *_tmp = (unsigned int *)(tp);              \
                int _n;                                                 \
-               ISC_REQUIRE((rp)->refs > 0);                            \
-               _n = --(rp)->refs;                                      \
+               ISC_REQUIRE((ref) > 0);                                 \
+               _n = --ref;                                             \
                if (_tmp != NULL)                                       \
                        *_tmp = _n;                                     \
        } while (0)
 
 #endif /* ISC_PLATFORM_USETHREADS */
 
+static inline
 isc_result_t
-isc_refcount_init(isc_refcount_t *ref, unsigned int n);
+isc_refcount_init(isc_refcount_t *ref, isc_refcount_t n) {
+       ISC_REQUIRE(ref);
+       *ref = n;
+       return (ISC_R_SUCCESS);
+}
 
 ISC_LANG_ENDDECLS
 
diff --git a/lib/isc/refcount.c b/lib/isc/refcount.c
deleted file mode 100644 (file)
index 0adc447..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * See the COPYRIGHT file distributed with this work for additional
- * information regarding copyright ownership.
- */
-
-
-#include <config.h>
-
-#include <stddef.h>
-
-#include <isc/mutex.h>
-#include <isc/refcount.h>
-#include <isc/result.h>
-#include <isc/util.h>
-
-isc_result_t
-isc_refcount_init(isc_refcount_t *ref, unsigned int n) {
-       REQUIRE(ref != NULL);
-
-       ref->refs = n;
-       return (ISC_R_SUCCESS);
-}