template <typename Type> struct ib_counter_element_t {
alignas(CPU_LEVEL1_DCACHE_LINESIZE) Type value;
};
/** Class for using fuzzy counters. The counter is multi-instance relaxed atomic sotheresultsarenotguaranteedtobe100%accuratebutclose
enough. */ template <typename Type, template <typename T> class Element = ib_atomic_counter_element_t, int N = 128 > struct ib_counter_t { /** Increment the counter by 1. */ void inc() { add(1); }
ib_counter_t& operator++() { inc(); return *this; }
/** Increment the counter by 1.
@param[in] index a reasonably thread-unique identifier */ void inc(size_t index) { add(index, 1); }
/** Add to the counter.
@param[in] n amount to be added */ void add(Type n) { add(size_t(my_pseudo_random()), n); }
/** Add to the counter. @param[in]indexareasonablythread-uniqueidentifier
@param[in] n amount to be added */
TPOOL_SUPPRESS_TSAN void add(size_t index, Type n) {
index = index % N;
ut_ad(index < UT_ARR_SIZE(m_counter));
m_counter[index].value += n;
}
/* @return total value - not 100% accurate, since it is relaxed atomic*/ operator Type() const {
Type total = 0;
for (constauto &counter : m_counter) {
total += counter.value;
}
return(total);
}
private:
static_assert(sizeof(Element<Type>) == CPU_LEVEL1_DCACHE_LINESIZE, ""); /** Array of counter elements */
alignas(CPU_LEVEL1_DCACHE_LINESIZE) Element<Type> m_counter[N];
};
#endif/* ut0counter_h */
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.