diff options
author | Eugene Kosov <claprix@yandex.ru> | 2021-03-11 10:56:54 +0300 |
---|---|---|
committer | Eugene Kosov <claprix@yandex.ru> | 2021-03-11 10:56:54 +0300 |
commit | 1654bfee4d0cd4867249729de4a609aebcc02d9a (patch) | |
tree | 02d8a46e1f455b3d09556133e8b24c4eef86f2cb | |
parent | ead86d0a5add9b7276f640da51f06879a0f9c4d4 (diff) | |
download | mariadb-git-bb-10.6-MDEV-21212.tar.gz |
remove initializationbb-10.6-MDEV-21212
-rw-r--r-- | include/distributable_counter.h | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/include/distributable_counter.h b/include/distributable_counter.h index eb309f6819c..144372f45b0 100644 --- a/include/distributable_counter.h +++ b/include/distributable_counter.h @@ -88,6 +88,9 @@ template <typename Integral, size_t Size> class counter_broker_array; // collection of counters. In a nutshell it's just an array of std::atomics. // Counters can be incremented directly but when contention becomes a problem, // this counter can be distributed via counter_broker_array. + +// WARNING: use as a global variable only! Otherwise, deal with uninitialized +// memory template <typename Integral, size_t Size> class distributable_counter_array { distributable_counter_array(const distributable_counter_array &)= delete; @@ -102,8 +105,8 @@ public: distributable_counter_array() noexcept { - for (auto &counter : counters_) - counter.store(0, std::memory_order_relaxed); + // No initialization of atomics here because we're relying on zero + // initialization for globals } __attribute__((warn_unused_result)) detail::strong_bumper<Integral> @@ -226,7 +229,7 @@ public: operator[](size_t idx) { assert(idx < Size); - return local()[idx]; + return broker_[idx]; } __attribute__((warn_unused_result)) Integral load(size_t idx) @@ -239,15 +242,8 @@ public: } private: - counter_broker_array<Integral, Size> &local() - { - // Meyers' singleton ensures that the broker will be initialized on the - // first access and thus will not slow down thread creation. - thread_local counter_broker_array<Integral, Size> broker(global_); - return broker; - } - distributable_counter_array<Integral, Size> global_; + counter_broker_array<Integral, Size> broker_{global_}; }; #endif |