From 93c04bb2fabc3a194d84b26ff45fa087bd20b478 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 17 Aug 2019 16:40:23 +0300 Subject: [PATCH] Use std::mutex instead of ArchMutex in IpcClientProxy --- src/lib/ipc/IpcClientProxy.cpp | 19 +++++++------------ src/lib/ipc/IpcClientProxy.h | 6 ++++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/lib/ipc/IpcClientProxy.cpp b/src/lib/ipc/IpcClientProxy.cpp index af85ecab..51042774 100644 --- a/src/lib/ipc/IpcClientProxy.cpp +++ b/src/lib/ipc/IpcClientProxy.cpp @@ -34,8 +34,6 @@ IpcClientProxy::IpcClientProxy(barrier::IStream& stream, IEventQueue* events) : m_stream(stream), m_clientType(kIpcClientUnknown), m_disconnecting(false), - m_readMutex(ARCH->newMutex()), - m_writeMutex(ARCH->newMutex()), m_events(events) { m_events->adoptHandler( @@ -71,14 +69,11 @@ IpcClientProxy::~IpcClientProxy() m_events->forIStream().outputShutdown(), m_stream.getEventTarget()); // don't delete the stream while it's being used. - ARCH->lockMutex(m_readMutex); - ARCH->lockMutex(m_writeMutex); - delete &m_stream; - ARCH->unlockMutex(m_readMutex); - ARCH->unlockMutex(m_writeMutex); - - ARCH->closeMutex(m_readMutex); - ARCH->closeMutex(m_writeMutex); + { + std::lock_guard lock_read(m_readMutex); + std::lock_guard lock_write(m_writeMutex); + delete &m_stream; + } } void @@ -99,7 +94,7 @@ void IpcClientProxy::handleData(const Event&, void*) { // don't allow the dtor to destroy the stream while we're using it. - ArchMutexLock lock(m_readMutex); + std::lock_guard lock(m_readMutex); LOG((CLOG_DEBUG "start ipc handle data")); @@ -139,7 +134,7 @@ IpcClientProxy::send(const IpcMessage& message) // don't allow other threads to write until we've finished the entire // message. stream write is locked, but only for that single write. // also, don't allow the dtor to destroy the stream while we're using it. - ArchMutexLock lock(m_writeMutex); + std::lock_guard lock(m_writeMutex); LOG((CLOG_DEBUG4 "ipc write: %d", message.type())); diff --git a/src/lib/ipc/IpcClientProxy.h b/src/lib/ipc/IpcClientProxy.h index eaa12c78..eb9f1e9b 100644 --- a/src/lib/ipc/IpcClientProxy.h +++ b/src/lib/ipc/IpcClientProxy.h @@ -23,6 +23,8 @@ #include "base/EventTypes.h" #include "base/Event.h" +#include + namespace barrier { class IStream; } class IpcMessage; class IpcCommandMessage; @@ -49,7 +51,7 @@ private: barrier::IStream& m_stream; EIpcClientType m_clientType; bool m_disconnecting; - ArchMutex m_readMutex; - ArchMutex m_writeMutex; + std::mutex m_readMutex; + std::mutex m_writeMutex; IEventQueue* m_events; };