From 2f08a35ac7d69245ea0472a646ae24477aa9ff65 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 23 Aug 2021 17:36:17 +0200 Subject: [PATCH] Fixed logger thread start/stop logic --- src/log.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/log.cpp b/src/log.cpp index 6d241c3..9142bcc 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -31,6 +31,7 @@ namespace log { int GLOBAL_LOG_LEVEL = 5; static volatile bool stopped = false; +static volatile bool worker_started = false; #ifdef _WIN32 static const HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); @@ -61,6 +62,8 @@ public: uv_mutex_init(&m_mutex); uv_thread_create(&m_worker, run_wrapper, this); + do {} while (!worker_started); + #ifdef _WIN32 DWORD dwConsoleMode; if (GetConsoleMode(hStdOut, &dwConsoleMode)) { @@ -82,6 +85,10 @@ public: FORCEINLINE void stop() { + if (stopped) { + return; + } + stopped = true; LOGINFO(0, "stopped"); uv_thread_join(&m_worker); @@ -121,6 +128,8 @@ private: NOINLINE void run() { + worker_started = true; + do { uv_mutex_lock(&m_mutex); uv_cond_wait(&m_cond, &m_mutex);