From cfae9d4ba4a813ef0767e052eada44db782698a4 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Tue, 19 Jan 2016 17:40:21 +0300 Subject: [PATCH] Global logging level now uses atomic to avoid multithreading issues. --- base/logging.cpp | 8 ++++---- base/logging.hpp | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/base/logging.cpp b/base/logging.cpp index 713903ae6a..7af5d1b8ae 100644 --- a/base/logging.cpp +++ b/base/logging.cpp @@ -92,10 +92,10 @@ namespace my } #ifdef DEBUG - LogLevel g_LogLevel = LDEBUG; - LogLevel g_LogAbortLevel = LERROR; + TLogLevel g_LogLevel = {LDEBUG}; + TLogLevel g_LogAbortLevel = {LERROR}; #else - LogLevel g_LogLevel = LINFO; - LogLevel g_LogAbortLevel = LCRITICAL; + TLogLevel g_LogLevel = {LINFO}; + TLogLevel g_LogAbortLevel = {LCRITICAL}; #endif } diff --git a/base/logging.hpp b/base/logging.hpp index f97af58be6..6c3987f9d1 100644 --- a/base/logging.hpp +++ b/base/logging.hpp @@ -1,8 +1,11 @@ #pragma once + #include "base/base.hpp" #include "base/internal/message.hpp" #include "base/src_point.hpp" +#include "std/atomic.hpp" + namespace my { enum LogLevel @@ -14,11 +17,12 @@ namespace my LCRITICAL }; + typedef atomic TLogLevel; typedef void (*LogMessageFn)(LogLevel level, SrcPoint const &, string const &); extern LogMessageFn LogMessage; - extern LogLevel g_LogLevel; - extern LogLevel g_LogAbortLevel; + extern TLogLevel g_LogLevel; + extern TLogLevel g_LogAbortLevel; /// @return Pointer to previous message function. LogMessageFn SetLogMessageFn(LogMessageFn fn);