From 0a89b5abfe02cca7e5003894f3295f49d439eb5a Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Wed, 3 Nov 2021 02:58:32 +0200 Subject: [PATCH] lib/ipc: Use standard mutex primitives in IpcLogOutputter --- src/lib/ipc/IpcLogOutputter.cpp | 13 ++++--------- src/lib/ipc/IpcLogOutputter.h | 5 +++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/lib/ipc/IpcLogOutputter.cpp b/src/lib/ipc/IpcLogOutputter.cpp index 72bd5c8d..d9a7e34d 100644 --- a/src/lib/ipc/IpcLogOutputter.cpp +++ b/src/lib/ipc/IpcLogOutputter.cpp @@ -41,8 +41,6 @@ IpcLogOutputter::IpcLogOutputter(IpcServer& ipcServer, EIpcClientType clientType m_sending(false), m_bufferThread(nullptr), m_running(false), - m_notifyCond(ARCH->newCondVar()), - m_notifyMutex(ARCH->newMutex()), m_bufferWaiting(false), m_bufferThreadId(0), m_bufferMaxSize(kBufferMaxSize), @@ -66,9 +64,6 @@ IpcLogOutputter::~IpcLogOutputter() m_bufferThread->wait(); delete m_bufferThread; } - - ARCH->closeCondVar(m_notifyCond); - ARCH->closeMutex(m_notifyMutex); } void @@ -148,8 +143,8 @@ void IpcLogOutputter::buffer_thread() try { while (isRunning()) { if (m_buffer.empty() || !m_ipcServer.hasClients(m_clientType)) { - ArchMutexLock lock(m_notifyMutex); - ARCH->waitCondVar(m_notifyCond, lock, -1); + std::unique_lock lock(notify_mutex_); + ARCH->wait_cond_var(notify_cv_, lock, -1); } sendBuffer(); @@ -165,8 +160,8 @@ void IpcLogOutputter::buffer_thread() void IpcLogOutputter::notifyBuffer() { - ArchMutexLock lock(m_notifyMutex); - ARCH->broadcastCondVar(m_notifyCond); + std::lock_guard lock(notify_mutex_); + notify_cv_.notify_all(); } std::string IpcLogOutputter::getChunk(size_t count) diff --git a/src/lib/ipc/IpcLogOutputter.h b/src/lib/ipc/IpcLogOutputter.h index 3f3ab0a6..90e5c467 100644 --- a/src/lib/ipc/IpcLogOutputter.h +++ b/src/lib/ipc/IpcLogOutputter.h @@ -25,6 +25,7 @@ #include "ipc/Ipc.h" #include +#include #include class IpcServer; @@ -106,8 +107,8 @@ private: bool m_sending; Thread* m_bufferThread; bool m_running; - ArchCond m_notifyCond; - ArchMutex m_notifyMutex; + std::condition_variable notify_cv_; + std::mutex notify_mutex_; bool m_bufferWaiting; IArchMultithread::ThreadID m_bufferThreadId;