From e85450e19d43ec2c8c18ae4319a8967705887b61 Mon Sep 17 00:00:00 2001 From: Robert Nix Date: Wed, 23 Nov 2022 20:01:05 -0600 Subject: [PATCH] Use unordered_set for LatchCounter storage --- storage/innobase/include/sync0types.h | 31 ++++++++------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/storage/innobase/include/sync0types.h b/storage/innobase/include/sync0types.h index 0b4ff55acba..48595fabea3 100644 --- a/storage/innobase/include/sync0types.h +++ b/storage/innobase/include/sync0types.h @@ -34,6 +34,7 @@ this program; if not, write to the Free Software Foundation, Inc., #define sync0types_h #include +#include #include #include "sync0sync.h" @@ -661,23 +662,7 @@ class LatchCounter { } /** @return the aggregate counter */ - Count *sum_register() UNIV_NOTHROW { - m_mutex.enter(); - - Count *count; - - if (m_counters.empty()) { - count = ut::new_withkey(UT_NEW_THIS_FILE_PSI_KEY); - m_counters.push_back(count); - } else { - ut_a(m_counters.size() == 1); - count = m_counters[0]; - } - - m_mutex.exit(); - - return (count); - } + Count *sum_register() UNIV_NOTHROW { return &m_sum; } /** Deregister the count. We don't do anything @param[in] count The count instance to deregister */ @@ -689,7 +674,7 @@ class LatchCounter { void single_register(Count *count) UNIV_NOTHROW { m_mutex.enter(); - m_counters.push_back(count); + m_counters.insert(count); m_mutex.exit(); } @@ -699,8 +684,7 @@ class LatchCounter { void single_deregister(Count *count) UNIV_NOTHROW { m_mutex.enter(); - m_counters.erase(std::remove(m_counters.begin(), m_counters.end(), count), - m_counters.end()); + m_counters.erase(count); m_mutex.exit(); } @@ -751,13 +735,16 @@ class LatchCounter { private: typedef OSMutex Mutex; - typedef std::vector Counters; + typedef std::unordered_set CountSet; /** Mutex protecting m_counters */ mutable Mutex m_mutex; /** Counters for the latches */ - Counters m_counters; + CountSet m_counters; + + /** Aggregate counter */ + Count m_sum; /** if true then we collect the data */ bool m_active; -- 2.34.1