diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2018-12-29 01:37:46 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2018-12-29 14:19:03 +0400 |
commit | 0f034e2e9661733a9662ac91318b7f02efa0c1a3 (patch) | |
tree | eab3dc05fa8206a28a517322f3c22efc04eb9098 /plugin | |
parent | 1e7df0e530ada53a3084a66affcd5ff0fcb90765 (diff) | |
download | mariadb-git-0f034e2e9661733a9662ac91318b7f02efa0c1a3.tar.gz |
time_collector transition to std::atomic
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/query_response_time/query_response_time.cc | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/plugin/query_response_time/query_response_time.cc b/plugin/query_response_time/query_response_time.cc index 5d6119d20ef..a669f7d4236 100644 --- a/plugin/query_response_time/query_response_time.cc +++ b/plugin/query_response_time/query_response_time.cc @@ -147,42 +147,36 @@ void print_time(char* buffer, std::size_t buffer_size, const char* format, class time_collector { + utility *m_utility; + Atomic_counter<uint32_t> m_count[OVERALL_POWER_COUNT + 1]; + Atomic_counter<uint64_t> m_total[OVERALL_POWER_COUNT + 1]; + public: - time_collector(utility& u) : m_utility(&u) - { } - ~time_collector() - { } - uint32 count(uint index) - { - return my_atomic_load32((int32*)&m_count[index]); - } - uint64 total(uint index) - { - return my_atomic_load64((int64*)&m_total[index]); - } -public: + time_collector(utility& u): m_utility(&u) { flush(); } + ~time_collector() { } + uint32_t count(uint index) { return m_count[index]; } + uint64_t total(uint index) { return m_total[index]; } void flush() { - memset((void*)&m_count,0,sizeof(m_count)); - memset((void*)&m_total,0,sizeof(m_total)); + for (auto i= 0; i < OVERALL_POWER_COUNT + 1; i++) + { + m_count[i]= 0; + m_total[i]= 0; + } } - void collect(uint64 time) + void collect(uint64_t time) { int i= 0; for(int count= m_utility->bound_count(); count > i; ++i) { if(m_utility->bound(i) > time) { - my_atomic_add32((int32*)(&m_count[i]), 1); - my_atomic_add64((int64*)(&m_total[i]), time); + m_count[i]++; + m_total[i]+= time; break; } } } -private: - utility* m_utility; - uint32 m_count[OVERALL_POWER_COUNT + 1]; - uint64 m_total[OVERALL_POWER_COUNT + 1]; }; class collector @@ -191,7 +185,6 @@ public: collector() : m_time(m_utility) { m_utility.setup(DEFAULT_BASE); - m_time.flush(); } public: void flush() |