Skip to content

Commit 5cdeb23

Browse files
authored
Update FlexCounter.cpp, use m_pollInterval in MUTEX lock (sonic-net#797)
m_pollInterval is used out of the MUTEX lock,when set to a smaller value, it may result of wait for a very long time.
1 parent 387e578 commit 5cdeb23

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

syncd/FlexCounter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1694,14 +1694,14 @@ void FlexCounter::flexCounterThreadRunFunction()
16941694
std::chrono::duration_cast<std::chrono::milliseconds>(finish - start).count());
16951695

16961696
uint32_t correction = delay % m_pollInterval;
1697-
1697+
correction = m_pollInterval - correction;
16981698
MUTEX_UNLOCK; // explicit unlock
16991699

17001700
SWSS_LOG_DEBUG("End of flex counter thread FC %s, took %d ms", m_instanceId.c_str(), delay);
17011701

17021702
std::unique_lock<std::mutex> lk(m_mtxSleep);
17031703

1704-
m_cvSleep.wait_for(lk, std::chrono::milliseconds(m_pollInterval - correction));
1704+
m_cvSleep.wait_for(lk, std::chrono::milliseconds(correction));
17051705

17061706
continue;
17071707
}

0 commit comments

Comments
 (0)