mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
Dispatcher: Minimize amount of time m_flush_mutex is held. (#132)
This commit is contained in:
@@ -204,7 +204,6 @@ void DispatcherBase::DispatchThreadMain() {
|
||||
|
||||
int count = 0;
|
||||
|
||||
std::unique_lock<std::mutex> 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<std::mutex> 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
|
||||
|
||||
Reference in New Issue
Block a user