From a78ddb50d5ab2211b8b2f0d6d43482ece59fe682 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sun, 24 Apr 2022 16:22:22 +0200 Subject: [PATCH] Fixed logger thread timing logic --- src/log.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/log.cpp b/src/log.cpp index 59c156e..45756d4 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -152,10 +152,13 @@ private: do { uv_mutex_lock(&m_mutex); - uv_cond_wait(&m_cond, &m_mutex); + if (m_readPos == m_writePos.load()) { + // Nothing to do, wait for the signal + uv_cond_wait(&m_cond, &m_mutex); + } uv_mutex_unlock(&m_mutex); - for (uint32_t writePos = m_writePos.load(); m_readPos < writePos; writePos = m_writePos.load()) { + for (uint32_t writePos = m_writePos.load(); m_readPos != writePos; writePos = m_writePos.load()) { // We have at least one log slot pending, possibly more than one // Process everything in a loop before reading m_writePos again do {