Use std::mutex instead of ArchMutex in Log
This commit is contained in:
parent
9df4741748
commit
d9d39040ae
|
@ -63,9 +63,6 @@ Log::Log()
|
||||||
{
|
{
|
||||||
assert(s_log == NULL);
|
assert(s_log == NULL);
|
||||||
|
|
||||||
// create mutex for multithread safe operation
|
|
||||||
m_mutex = ARCH->newMutex();
|
|
||||||
|
|
||||||
// other initalization
|
// other initalization
|
||||||
m_maxPriority = g_defaultMaxPriority;
|
m_maxPriority = g_defaultMaxPriority;
|
||||||
m_maxNewlineLength = 0;
|
m_maxNewlineLength = 0;
|
||||||
|
@ -90,7 +87,6 @@ Log::~Log()
|
||||||
index != m_alwaysOutputters.end(); ++index) {
|
index != m_alwaysOutputters.end(); ++index) {
|
||||||
delete *index;
|
delete *index;
|
||||||
}
|
}
|
||||||
ARCH->closeMutex(m_mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Log*
|
Log*
|
||||||
|
@ -214,7 +210,7 @@ Log::insert(ILogOutputter* outputter, bool alwaysAtHead)
|
||||||
{
|
{
|
||||||
assert(outputter != NULL);
|
assert(outputter != NULL);
|
||||||
|
|
||||||
ArchMutexLock lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
if (alwaysAtHead) {
|
if (alwaysAtHead) {
|
||||||
m_alwaysOutputters.push_front(outputter);
|
m_alwaysOutputters.push_front(outputter);
|
||||||
}
|
}
|
||||||
|
@ -237,7 +233,7 @@ Log::insert(ILogOutputter* outputter, bool alwaysAtHead)
|
||||||
void
|
void
|
||||||
Log::remove(ILogOutputter* outputter)
|
Log::remove(ILogOutputter* outputter)
|
||||||
{
|
{
|
||||||
ArchMutexLock lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
m_outputters.remove(outputter);
|
m_outputters.remove(outputter);
|
||||||
m_alwaysOutputters.remove(outputter);
|
m_alwaysOutputters.remove(outputter);
|
||||||
}
|
}
|
||||||
|
@ -245,7 +241,7 @@ Log::remove(ILogOutputter* outputter)
|
||||||
void
|
void
|
||||||
Log::pop_front(bool alwaysAtHead)
|
Log::pop_front(bool alwaysAtHead)
|
||||||
{
|
{
|
||||||
ArchMutexLock lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
OutputterList* list = alwaysAtHead ? &m_alwaysOutputters : &m_outputters;
|
OutputterList* list = alwaysAtHead ? &m_alwaysOutputters : &m_outputters;
|
||||||
if (!list->empty()) {
|
if (!list->empty()) {
|
||||||
delete list->front();
|
delete list->front();
|
||||||
|
@ -271,14 +267,14 @@ Log::setFilter(const char* maxPriority)
|
||||||
void
|
void
|
||||||
Log::setFilter(int maxPriority)
|
Log::setFilter(int maxPriority)
|
||||||
{
|
{
|
||||||
ArchMutexLock lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
m_maxPriority = maxPriority;
|
m_maxPriority = maxPriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Log::getFilter() const
|
Log::getFilter() const
|
||||||
{
|
{
|
||||||
ArchMutexLock lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
return m_maxPriority;
|
return m_maxPriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +285,7 @@ Log::output(ELevel priority, char* msg)
|
||||||
assert(msg != NULL);
|
assert(msg != NULL);
|
||||||
if (!msg) return;
|
if (!msg) return;
|
||||||
|
|
||||||
ArchMutexLock lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
OutputterList::const_iterator i;
|
OutputterList::const_iterator i;
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "common/stdlist.h"
|
#include "common/stdlist.h"
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#define CLOG (Log::getInstance())
|
#define CLOG (Log::getInstance())
|
||||||
#define BYE "\nTry `%s --help' for more information."
|
#define BYE "\nTry `%s --help' for more information."
|
||||||
|
@ -132,7 +133,7 @@ private:
|
||||||
|
|
||||||
static Log* s_log;
|
static Log* s_log;
|
||||||
|
|
||||||
ArchMutex m_mutex;
|
mutable std::mutex m_mutex;
|
||||||
OutputterList m_outputters;
|
OutputterList m_outputters;
|
||||||
OutputterList m_alwaysOutputters;
|
OutputterList m_alwaysOutputters;
|
||||||
int m_maxNewlineLength;
|
int m_maxNewlineLength;
|
||||||
|
|
Loading…
Reference in New Issue