isc_statsmulti_update_if_greater(isc_statsmulti_t *stats, isc_statscounter_t counter, isc_statscounter_t value);
/*%<
* Update a highwater counter if the provided value is greater than the current per-thread value.
- * Only works on counters in the range [n_additive, n_additive + n_max).
+ * Takes counter values from 0 to n_max-1 and internally maps to the highwater range.
*
* Requires:
*\li 'stats' is a valid isc_statsmulti_t.
*
- *\li counter is in the highwater range for the stats specified on creation.
+ *\li counter is less than n_max specified on creation.
*/
isc_statscounter_t
isc_statsmulti_get_highwater(isc_statsmulti_t *stats, isc_statscounter_t counter);
/*%<
* Returns the maximum value across all threads for a highwater counter.
- * Only works on counters in the range [n_additive, n_additive + n_max).
+ * Takes counter values from 0 to n_max-1 and internally maps to the highwater range.
*
* Requires:
*\li 'stats' is a valid isc_statsmulti_t.
*
- *\li counter is in the highwater range for the stats specified on creation.
+ *\li counter is less than n_max specified on creation.
*/
\ No newline at end of file
void
isc_statsmulti_update_if_greater(isc_statsmulti_t *stats, isc_statscounter_t counter, isc_statscounter_t value) {
REQUIRE(ISC_STATSMULTI_VALID(stats));
- REQUIRE(counter >= stats->n_additive);
- REQUIRE(counter < stats->ncounters);
+ REQUIRE(counter < stats->n_max);
+
+ /* Map counter to internal highwater position */
+ isc_statscounter_t internal_counter = stats->n_additive + counter;
isc_tid_t tid = isc_tid();
int thread_id = ISC_MAX(tid, 0);
if (thread_id >= stats->num_threads) {
thread_id = 0;
}
- int index = thread_id * stats->per_thread_capacity + counter;
+ int index = thread_id * stats->per_thread_capacity + internal_counter;
/* Atomically update if the new value is greater than current */
isc_statscounter_t current = atomic_load_relaxed(&stats->counters[index]);
isc_statscounter_t
isc_statsmulti_get_highwater(isc_statsmulti_t *stats, isc_statscounter_t counter) {
REQUIRE(ISC_STATSMULTI_VALID(stats));
- REQUIRE(counter >= stats->n_additive);
- REQUIRE(counter < stats->ncounters);
+ REQUIRE(counter < stats->n_max);
+
+ /* Map counter to internal highwater position */
+ isc_statscounter_t internal_counter = stats->n_additive + counter;
isc_statscounter_t max_value = 0;
/* Find maximum value across all threads */
for (int thread = 0; thread < stats->num_threads; thread++) {
- int index = thread * stats->per_thread_capacity + counter;
+ int index = thread * stats->per_thread_capacity + internal_counter;
isc_statscounter_t value = atomic_load_acquire(&stats->counters[index]);
if (value > max_value) {
max_value = value;