]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Return the old counter value in `isc_stats_increment`
authorAydın Mercan <aydin@isc.org>
Tue, 30 Apr 2024 11:37:26 +0000 (14:37 +0300)
committerAydın Mercan <aydin@isc.org>
Fri, 10 May 2024 09:08:52 +0000 (12:08 +0300)
Returning the value allows for better high-water tracking without
running into edge cases like the following:

0. The counter is at value X
1. Increment the value (X+1)
2. The value is decreased multiple times in another threads (X+1-Y)
3. Get the value (X+1-Y)
4. Update-if-greater misses the X+1 value which should have been the
   high-water

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

index 23a076eba9784f03ff938751876133e71bde9dac..f6520969c805cbef6ffcdd37ab78652bdd5f885b 100644 (file)
@@ -137,10 +137,10 @@ isc_stats_ncounters(isc_stats_t *stats);
  *
  */
 
-void
+isc_statscounter_t
 isc_stats_increment(isc_stats_t *stats, isc_statscounter_t counter);
 /*%<
- * Increment the counter-th counter of stats.
+ * Increment the counter-th counter of stats and return the old value.
  *
  * Requires:
  *\li  'stats' is a valid isc_stats_t.
index 07a88fb6c956152fdecb20013d45434aa1743a2e..2f7e8bcde131fd877c0039cc9466d00d55c4a944 100644 (file)
@@ -97,12 +97,12 @@ isc_stats_create(isc_mem_t *mctx, isc_stats_t **statsp, int ncounters) {
        *statsp = stats;
 }
 
-void
+isc_statscounter_t
 isc_stats_increment(isc_stats_t *stats, isc_statscounter_t counter) {
        REQUIRE(ISC_STATS_VALID(stats));
        REQUIRE(counter < stats->ncounters);
 
-       atomic_fetch_add_relaxed(&stats->counters[counter], 1);
+       return (atomic_fetch_add_relaxed(&stats->counters[counter], 1));
 }
 
 void
index d7e79443cf461a02d05628610b24439bba1e834a..c904d7f38cec84b88568928b8a79d652f2d92fff 100644 (file)
@@ -124,7 +124,7 @@ ns_stats_detach(ns_stats_t **statsp);
 void
 ns_stats_create(isc_mem_t *mctx, int ncounters, ns_stats_t **statsp);
 
-void
+isc_statscounter_t
 ns_stats_increment(ns_stats_t *stats, isc_statscounter_t counter);
 
 void
index 84dd0ab029c31d7b14bc3709f9d80fc47ebf7c11..791c08a7566e2affb9a7083329b7c056433ff992 100644 (file)
@@ -78,11 +78,11 @@ ns_stats_create(isc_mem_t *mctx, int ncounters, ns_stats_t **statsp) {
 /*%
  * Increment/Decrement methods
  */
-void
+isc_statscounter_t
 ns_stats_increment(ns_stats_t *stats, isc_statscounter_t counter) {
        REQUIRE(NS_STATS_VALID(stats));
 
-       isc_stats_increment(stats->counters, counter);
+       return (isc_stats_increment(stats->counters, counter));
 }
 
 void