From 5dddf529f75a943332c4e16d3bf4fab10e819c8d Mon Sep 17 00:00:00 2001 From: Marian Pritsak Date: Mon, 6 Nov 2017 21:24:25 +0200 Subject: [PATCH] [syncd_flex_counter.cpp]: Move lock_guard to narrow scope (#256) lock_guard holds mutex during sleep, which does not allow other threads to acquire it for most of time. It is moved to a scope that actually needs this mutex. Signed-off-by: marian-pritsak --- syncd/syncd_flex_counter.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/syncd/syncd_flex_counter.cpp b/syncd/syncd_flex_counter.cpp index 7d3f5ec8ee..f87538c5f8 100644 --- a/syncd/syncd_flex_counter.cpp +++ b/syncd/syncd_flex_counter.cpp @@ -378,10 +378,11 @@ void FlexCounter::flexCounterThread(void) while (m_runFlexCounterThread) { - - std::lock_guard lock(g_mutex); - collectCounters(countersTable); - runPlugins(db); + { + std::lock_guard lock(g_mutex); + collectCounters(countersTable); + runPlugins(db); + } std::unique_lock lk(m_mtxSleep); m_cvSleep.wait_for(lk, std::chrono::milliseconds(FLEX_COUNTER_POLL_MSECS));