Skip to content

Commit 5dddf52

Browse files
marian-pritsakqiluo-msft
authored andcommitted
[syncd_flex_counter.cpp]: Move lock_guard to narrow scope (sonic-net#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 <[email protected]>
1 parent 996a81a commit 5dddf52

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

syncd/syncd_flex_counter.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,11 @@ void FlexCounter::flexCounterThread(void)
378378

379379
while (m_runFlexCounterThread)
380380
{
381-
382-
std::lock_guard<std::mutex> lock(g_mutex);
383-
collectCounters(countersTable);
384-
runPlugins(db);
381+
{
382+
std::lock_guard<std::mutex> lock(g_mutex);
383+
collectCounters(countersTable);
384+
runPlugins(db);
385+
}
385386

386387
std::unique_lock<std::mutex> lk(m_mtxSleep);
387388
m_cvSleep.wait_for(lk, std::chrono::milliseconds(FLEX_COUNTER_POLL_MSECS));

0 commit comments

Comments
 (0)