From d9d39040ae783a99980ca11d53751e27f5780508 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 17 Aug 2019 16:40:21 +0300 Subject: [PATCH] Use std::mutex instead of ArchMutex in Log --- src/lib/base/Log.cpp | 16 ++++++---------- src/lib/base/Log.h | 3 ++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/lib/base/Log.cpp b/src/lib/base/Log.cpp index 823bf6d1..1252ed9f 100644 --- a/src/lib/base/Log.cpp +++ b/src/lib/base/Log.cpp @@ -63,9 +63,6 @@ Log::Log() { assert(s_log == NULL); - // create mutex for multithread safe operation - m_mutex = ARCH->newMutex(); - // other initalization m_maxPriority = g_defaultMaxPriority; m_maxNewlineLength = 0; @@ -90,7 +87,6 @@ Log::~Log() index != m_alwaysOutputters.end(); ++index) { delete *index; } - ARCH->closeMutex(m_mutex); } Log* @@ -214,7 +210,7 @@ Log::insert(ILogOutputter* outputter, bool alwaysAtHead) { assert(outputter != NULL); - ArchMutexLock lock(m_mutex); + std::lock_guard lock(m_mutex); if (alwaysAtHead) { m_alwaysOutputters.push_front(outputter); } @@ -237,7 +233,7 @@ Log::insert(ILogOutputter* outputter, bool alwaysAtHead) void Log::remove(ILogOutputter* outputter) { - ArchMutexLock lock(m_mutex); + std::lock_guard lock(m_mutex); m_outputters.remove(outputter); m_alwaysOutputters.remove(outputter); } @@ -245,7 +241,7 @@ Log::remove(ILogOutputter* outputter) void Log::pop_front(bool alwaysAtHead) { - ArchMutexLock lock(m_mutex); + std::lock_guard lock(m_mutex); OutputterList* list = alwaysAtHead ? &m_alwaysOutputters : &m_outputters; if (!list->empty()) { delete list->front(); @@ -271,14 +267,14 @@ Log::setFilter(const char* maxPriority) void Log::setFilter(int maxPriority) { - ArchMutexLock lock(m_mutex); + std::lock_guard lock(m_mutex); m_maxPriority = maxPriority; } int Log::getFilter() const { - ArchMutexLock lock(m_mutex); + std::lock_guard lock(m_mutex); return m_maxPriority; } @@ -289,7 +285,7 @@ Log::output(ELevel priority, char* msg) assert(msg != NULL); if (!msg) return; - ArchMutexLock lock(m_mutex); + std::lock_guard lock(m_mutex); OutputterList::const_iterator i; diff --git a/src/lib/base/Log.h b/src/lib/base/Log.h index 1d09be22..0ed458f8 100644 --- a/src/lib/base/Log.h +++ b/src/lib/base/Log.h @@ -24,6 +24,7 @@ #include "common/stdlist.h" #include +#include #define CLOG (Log::getInstance()) #define BYE "\nTry `%s --help' for more information." @@ -132,7 +133,7 @@ private: static Log* s_log; - ArchMutex m_mutex; + mutable std::mutex m_mutex; OutputterList m_outputters; OutputterList m_alwaysOutputters; int m_maxNewlineLength;