2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-01 06:55:30 +00:00

Return the old counter value in isc_stats_increment

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
This commit is contained in:
Aydın Mercan
2024-04-30 14:37:26 +03:00
parent ced011f05a
commit 09e4fb2ffa
4 changed files with 7 additions and 7 deletions

View 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); 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: * Requires:
*\li 'stats' is a valid isc_stats_t. *\li 'stats' is a valid isc_stats_t.

View File

@@ -97,12 +97,12 @@ isc_stats_create(isc_mem_t *mctx, isc_stats_t **statsp, int ncounters) {
*statsp = stats; *statsp = stats;
} }
void isc_statscounter_t
isc_stats_increment(isc_stats_t *stats, isc_statscounter_t counter) { isc_stats_increment(isc_stats_t *stats, isc_statscounter_t counter) {
REQUIRE(ISC_STATS_VALID(stats)); REQUIRE(ISC_STATS_VALID(stats));
REQUIRE(counter < stats->ncounters); REQUIRE(counter < stats->ncounters);
atomic_fetch_add_relaxed(&stats->counters[counter], 1); return (atomic_fetch_add_relaxed(&stats->counters[counter], 1));
} }
void void

View File

@@ -124,7 +124,7 @@ ns_stats_detach(ns_stats_t **statsp);
void void
ns_stats_create(isc_mem_t *mctx, int ncounters, ns_stats_t **statsp); 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); ns_stats_increment(ns_stats_t *stats, isc_statscounter_t counter);
void void

View File

@@ -78,11 +78,11 @@ ns_stats_create(isc_mem_t *mctx, int ncounters, ns_stats_t **statsp) {
/*% /*%
* Increment/Decrement methods * Increment/Decrement methods
*/ */
void isc_statscounter_t
ns_stats_increment(ns_stats_t *stats, isc_statscounter_t counter) { ns_stats_increment(ns_stats_t *stats, isc_statscounter_t counter) {
REQUIRE(NS_STATS_VALID(stats)); REQUIRE(NS_STATS_VALID(stats));
isc_stats_increment(stats->counters, counter); return (isc_stats_increment(stats->counters, counter));
} }
void void