Use std::mutex instead of ArchMutex in IpcLogOutputter

This commit is contained in:
Povilas Kanapickas 2019-08-17 16:40:24 +03:00
parent 93c04bb2fa
commit 83d0639230
2 changed files with 8 additions and 11 deletions

View File

@ -39,7 +39,6 @@ enum EIpcLogOutputter {
IpcLogOutputter::IpcLogOutputter(IpcServer& ipcServer, EIpcClientType clientType, bool useThread) : IpcLogOutputter::IpcLogOutputter(IpcServer& ipcServer, EIpcClientType clientType, bool useThread) :
m_ipcServer(ipcServer), m_ipcServer(ipcServer),
m_bufferMutex(ARCH->newMutex()),
m_sending(false), m_sending(false),
m_bufferThread(nullptr), m_bufferThread(nullptr),
m_running(false), m_running(false),
@ -52,8 +51,7 @@ IpcLogOutputter::IpcLogOutputter(IpcServer& ipcServer, EIpcClientType clientType
m_bufferRateTimeLimit(kBufferRateTimeLimit), m_bufferRateTimeLimit(kBufferRateTimeLimit),
m_bufferWriteCount(0), m_bufferWriteCount(0),
m_bufferRateStart(ARCH->time()), m_bufferRateStart(ARCH->time()),
m_clientType(clientType), m_clientType(clientType)
m_runningMutex(ARCH->newMutex())
{ {
if (useThread) { if (useThread) {
m_bufferThread = new Thread(new TMethodJob<IpcLogOutputter>( m_bufferThread = new Thread(new TMethodJob<IpcLogOutputter>(
@ -65,8 +63,6 @@ IpcLogOutputter::~IpcLogOutputter()
{ {
close(); close();
ARCH->closeMutex(m_bufferMutex);
if (m_bufferThread != nullptr) { if (m_bufferThread != nullptr) {
m_bufferThread->cancel(); m_bufferThread->cancel();
m_bufferThread->wait(); m_bufferThread->wait();
@ -86,7 +82,7 @@ void
IpcLogOutputter::close() IpcLogOutputter::close()
{ {
if (m_bufferThread != nullptr) { if (m_bufferThread != nullptr) {
ArchMutexLock lock(m_runningMutex); std::lock_guard<std::mutex> lock(m_runningMutex);
m_running = false; m_running = false;
notifyBuffer(); notifyBuffer();
m_bufferThread->wait(5); m_bufferThread->wait(5);
@ -116,7 +112,7 @@ IpcLogOutputter::write(ELevel, const char* text)
void void
IpcLogOutputter::appendBuffer(const String& text) IpcLogOutputter::appendBuffer(const String& text)
{ {
ArchMutexLock lock(m_bufferMutex); std::lock_guard<std::mutex> lock(m_bufferMutex);
double elapsed = ARCH->time() - m_bufferRateStart; double elapsed = ARCH->time() - m_bufferRateStart;
if (elapsed < m_bufferRateTimeLimit) { if (elapsed < m_bufferRateTimeLimit) {
@ -143,7 +139,7 @@ IpcLogOutputter::appendBuffer(const String& text)
bool bool
IpcLogOutputter::isRunning() IpcLogOutputter::isRunning()
{ {
ArchMutexLock lock(m_runningMutex); std::lock_guard<std::mutex> lock(m_runningMutex);
return m_running; return m_running;
} }
@ -180,7 +176,7 @@ IpcLogOutputter::notifyBuffer()
String String
IpcLogOutputter::getChunk(size_t count) IpcLogOutputter::getChunk(size_t count)
{ {
ArchMutexLock lock(m_bufferMutex); std::lock_guard<std::mutex> lock(m_bufferMutex);
if (m_buffer.size() < count) { if (m_buffer.size() < count) {
count = m_buffer.size(); count = m_buffer.size();

View File

@ -24,6 +24,7 @@
#include "ipc/Ipc.h" #include "ipc/Ipc.h"
#include <deque> #include <deque>
#include <mutex>
class IpcServer; class IpcServer;
class Event; class Event;
@ -100,7 +101,7 @@ private:
IpcServer& m_ipcServer; IpcServer& m_ipcServer;
Buffer m_buffer; Buffer m_buffer;
ArchMutex m_bufferMutex; std::mutex m_bufferMutex;
bool m_sending; bool m_sending;
Thread* m_bufferThread; Thread* m_bufferThread;
bool m_running; bool m_running;
@ -115,5 +116,5 @@ private:
UInt16 m_bufferWriteCount; UInt16 m_bufferWriteCount;
double m_bufferRateStart; double m_bufferRateStart;
EIpcClientType m_clientType; EIpcClientType m_clientType;
ArchMutex m_runningMutex; std::mutex m_runningMutex;
}; };