Skip to content

Commit

Permalink
[syncd_flex_counter.cpp]: Move lock_guard to narrow scope (sonic-net#256
Browse files Browse the repository at this point in the history
)

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]>
  • Loading branch information
marian-pritsak authored and qiluo-msft committed Nov 6, 2017
1 parent 996a81a commit 5dddf52
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions syncd/syncd_flex_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,11 @@ void FlexCounter::flexCounterThread(void)

while (m_runFlexCounterThread)
{

std::lock_guard<std::mutex> lock(g_mutex);
collectCounters(countersTable);
runPlugins(db);
{
std::lock_guard<std::mutex> lock(g_mutex);
collectCounters(countersTable);
runPlugins(db);
}

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

0 comments on commit 5dddf52

Please sign in to comment.