From 1d336996be69536ac9e8a398388352951caec9bc Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 21 Oct 2016 20:01:41 -0700 Subject: [PATCH] Dispatcher: Minimize amount of time m_flush_mutex is held. (#132) --- src/Dispatcher.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Dispatcher.cpp b/src/Dispatcher.cpp index 672a87eb0f..f8655abe93 100644 --- a/src/Dispatcher.cpp +++ b/src/Dispatcher.cpp @@ -204,7 +204,6 @@ void DispatcherBase::DispatchThreadMain() { int count = 0; - std::unique_lock flush_lock(m_flush_mutex); while (m_active) { // handle loop taking too long auto start = std::chrono::steady_clock::now(); @@ -213,9 +212,11 @@ void DispatcherBase::DispatchThreadMain() { // wait for periodic or when flushed timeout_time += std::chrono::milliseconds(m_update_rate); + std::unique_lock flush_lock(m_flush_mutex); m_flush_cv.wait_until(flush_lock, timeout_time, [&] { return !m_active || m_do_flush; }); m_do_flush = false; + flush_lock.unlock(); if (!m_active) break; // in case we were woken up to terminate // perform periodic persistent save