]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Convert isc_statsmulti to use ISC_REFCOUNT_IMPL
authorAlessio Podda <alessio@isc.org>
Wed, 25 Mar 2026 09:22:32 +0000 (10:22 +0100)
committerAlessio Podda <alessio@isc.org>
Thu, 26 Mar 2026 09:19:25 +0000 (10:19 +0100)
Instead of using hand-rolled attach and detach function, this commit
declares the same functions through the ISC_REFCOUNT_IMPL macro.

lib/isc/include/isc/statsmulti.h
lib/isc/statsmulti.c

index 7785662d842d3f140f44f70de19ef63215b3bdf6..ce504924b813c2562a0fe3abcb8dbc5daf8df730 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <inttypes.h>
 
+#include <isc/refcount.h>
 #include <isc/types.h>
 
 typedef struct isc_statsmulti isc_statsmulti_t; /*%< Statistics Multi */
@@ -44,25 +45,7 @@ isc_statsmulti_create(isc_mem_t *mctx, isc_statsmulti_t **statsp,
  *\li  'statsp' != NULL && '*statsp' == NULL.
  */
 
-void
-isc_statsmulti_attach(isc_statsmulti_t *stats, isc_statsmulti_t **statsp);
-/*%<
- * Attach to a statistics set.
- *
- * Requires:
- *\li  'stats' is a valid isc_statsmulti_t.
- *
- *\li  'statsp' != NULL && '*statsp' == NULL
- */
-
-void
-isc_statsmulti_detach(isc_statsmulti_t **statsp);
-/*%<
- * Detaches from the statistics set.
- *
- * Requires:
- *\li  'statsp' != NULL and '*statsp' is a valid isc_statsmulti_t.
- */
+ISC_REFCOUNT_DECL(isc_statsmulti);
 
 void
 isc_statsmulti_increment(isc_statsmulti_t *stats, isc_statscounter_t counter);
index 70f9918262842fafa98d86241efde2733c8cef6c..f509f4811483704df55cf7cb4d94b57d5354557c 100644 (file)
@@ -84,33 +84,18 @@ isc_statsmulti_create(isc_mem_t *mctx, isc_statsmulti_t **statsp,
        *statsp = stats;
 }
 
-void
-isc_statsmulti_attach(isc_statsmulti_t *stats, isc_statsmulti_t **statsp) {
+static void
+isc__statsmulti_destroy(isc_statsmulti_t *stats) {
        REQUIRE(ISC_STATSMULTI_VALID(stats));
-       REQUIRE(statsp != NULL && *statsp == NULL);
 
-       isc_refcount_increment(&stats->references);
-       *statsp = stats;
+       size_t alloc_size = stats->per_thread_capacity *
+                           stats->num_threads_plus_one *
+                           sizeof(isc_atomic_statscounter_t);
+       isc_mem_put(stats->mctx, stats->counters, alloc_size);
+       isc_mem_putanddetach(&stats->mctx, stats, sizeof(*stats));
 }
 
-void
-isc_statsmulti_detach(isc_statsmulti_t **statsp) {
-       isc_statsmulti_t *stats;
-
-       REQUIRE(statsp != NULL && ISC_STATSMULTI_VALID(*statsp));
-
-       stats = *statsp;
-       *statsp = NULL;
-
-       if (isc_refcount_decrement(&stats->references) == 1) {
-               isc_refcount_destroy(&stats->references);
-               size_t alloc_size = stats->per_thread_capacity *
-                                   stats->num_threads_plus_one *
-                                   sizeof(isc_atomic_statscounter_t);
-               isc_mem_put(stats->mctx, stats->counters, alloc_size);
-               isc_mem_putanddetach(&stats->mctx, stats, sizeof(*stats));
-       }
-}
+ISC_REFCOUNT_IMPL(isc_statsmulti, isc__statsmulti_destroy);
 
 void
 isc_statsmulti_increment(isc_statsmulti_t *stats, isc_statscounter_t counter) {