]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Move atomic statscounter next to the non-atomic definition
authorAydın Mercan <aydin@isc.org>
Mon, 11 Dec 2023 14:26:04 +0000 (17:26 +0300)
committerAydın Mercan <aydin@isc.org>
Wed, 3 Jan 2024 17:36:35 +0000 (20:36 +0300)
(cherry picked from commit 9c4dd863a6876d23b1a40f9f4d89b73d1ff30061)

lib/isc/include/isc/types.h
lib/isc/stats.c

index 7e0fc021dfdc29363cfad98e9deffc60b6a1e358..7d6b94dd615cba8293a442ed6ca93dd2bc92fdcf 100644 (file)
@@ -20,6 +20,7 @@
  * OS-specific types, from the OS-specific include directories.
  */
 #include <inttypes.h>
+#include <stdatomic.h>
 #include <stdbool.h>
 
 #include <isc/offset.h>
@@ -74,10 +75,11 @@ typedef struct isc_rwlock    isc_rwlock_t;        /*%< Read Write Lock */
 typedef struct isc_sockaddr     isc_sockaddr_t;      /*%< Socket Address */
 typedef ISC_LIST(isc_sockaddr_t) isc_sockaddrlist_t;  /*%< Socket Address List
                                                       * */
-typedef struct isc_stats  isc_stats_t;               /*%< Statistics */
-typedef int_fast64_t     isc_statscounter_t;
-typedef struct isc_symtab isc_symtab_t;                /*%< Symbol Table */
-typedef struct isc_task          isc_task_t;           /*%< Task */
+typedef struct isc_stats    isc_stats_t;             /*%< Statistics */
+typedef int_fast64_t       isc_statscounter_t;
+typedef atomic_int_fast64_t isc_atomic_statscounter_t;
+typedef struct isc_symtab   isc_symtab_t;      /*%< Symbol Table */
+typedef struct isc_task            isc_task_t;         /*%< Task */
 typedef ISC_LIST(isc_task_t) isc_tasklist_t;   /*%< Task List */
 typedef struct isc_taskmgr    isc_taskmgr_t;   /*%< Task Manager */
 typedef struct isc_textregion isc_textregion_t; /*%< Text Region */
index 86d483304212deb9facae33e63ea6efb4cab048c..183030e4f81024ebe3ce7ce13f1d20fcec91e3f0 100644 (file)
 #define ISC_STATS_MAGIC           ISC_MAGIC('S', 't', 'a', 't')
 #define ISC_STATS_VALID(x) ISC_MAGIC_VALID(x, ISC_STATS_MAGIC)
 
-typedef atomic_int_fast64_t isc__atomic_statcounter_t;
-
 /*
  * Statistics are counted with an atomic int_fast64_t but exported to functions
- * taking int64_t (isc_stats_dumper_t). A 128-bit native and fast architecture
+ * taking uint64_t (isc_stats_dumper_t). A 128-bit native and fast architecture
  * doesn't exist in reality so these two are the same thing in practise.
  * However, a silent truncation happening silently in the future is still not
  * acceptable.
  */
-STATIC_ASSERT(sizeof(isc__atomic_statcounter_t) <= sizeof(int64_t),
+STATIC_ASSERT(sizeof(isc_statscounter_t) <= sizeof(uint64_t),
              "Exported statistics must fit into the statistic counter size");
 
 struct isc_stats {
@@ -45,7 +43,7 @@ struct isc_stats {
        isc_mem_t *mctx;
        isc_refcount_t references;
        int ncounters;
-       isc__atomic_statcounter_t *counters;
+       isc_atomic_statscounter_t *counters;
 };
 
 static isc_result_t
@@ -56,7 +54,7 @@ create_stats(isc_mem_t *mctx, int ncounters, isc_stats_t **statsp) {
        REQUIRE(statsp != NULL && *statsp == NULL);
 
        stats = isc_mem_get(mctx, sizeof(*stats));
-       counters_alloc_size = sizeof(isc__atomic_statcounter_t) * ncounters;
+       counters_alloc_size = sizeof(isc_atomic_statscounter_t) * ncounters;
        stats->counters = isc_mem_get(mctx, counters_alloc_size);
        isc_refcount_init(&stats->references, 1);
        for (int i = 0; i < ncounters; i++) {
@@ -92,7 +90,7 @@ isc_stats_detach(isc_stats_t **statsp) {
        if (isc_refcount_decrement(&stats->references) == 1) {
                isc_refcount_destroy(&stats->references);
                isc_mem_put(stats->mctx, stats->counters,
-                           sizeof(isc__atomic_statcounter_t) *
+                           sizeof(isc_atomic_statscounter_t) *
                                    stats->ncounters);
                isc_mem_putanddetach(&stats->mctx, stats, sizeof(*stats));
        }
@@ -135,7 +133,8 @@ isc_stats_dump(isc_stats_t *stats, isc_stats_dumper_t dump_fn, void *arg,
        REQUIRE(ISC_STATS_VALID(stats));
 
        for (i = 0; i < stats->ncounters; i++) {
-               int_fast64_t counter = atomic_load_acquire(&stats->counters[i]);
+               isc_statscounter_t counter =
+                       atomic_load_acquire(&stats->counters[i]);
                if ((options & ISC_STATSDUMP_VERBOSE) == 0 && counter == 0) {
                        continue;
                }
@@ -179,7 +178,7 @@ void
 isc_stats_resize(isc_stats_t **statsp, int ncounters) {
        isc_stats_t *stats;
        size_t counters_alloc_size;
-       isc__atomic_statcounter_t *newcounters;
+       isc_atomic_statscounter_t *newcounters;
 
        REQUIRE(statsp != NULL && *statsp != NULL);
        REQUIRE(ISC_STATS_VALID(*statsp));
@@ -192,7 +191,7 @@ isc_stats_resize(isc_stats_t **statsp, int ncounters) {
        }
 
        /* Grow number of counters. */
-       counters_alloc_size = sizeof(isc__atomic_statcounter_t) * ncounters;
+       counters_alloc_size = sizeof(isc_atomic_statscounter_t) * ncounters;
        newcounters = isc_mem_get(stats->mctx, counters_alloc_size);
        for (int i = 0; i < ncounters; i++) {
                atomic_init(&newcounters[i], 0);
@@ -202,7 +201,7 @@ isc_stats_resize(isc_stats_t **statsp, int ncounters) {
                atomic_store_release(&newcounters[i], counter);
        }
        isc_mem_put(stats->mctx, stats->counters,
-                   sizeof(isc__atomic_statcounter_t) * stats->ncounters);
+                   sizeof(isc_atomic_statscounter_t) * stats->ncounters);
        stats->counters = newcounters;
        stats->ncounters = ncounters;
 }