aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ipc
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2019-10-05 21:10:01 -0400
committerLibravatarUnit 193 <unit193@ubuntu.com>2019-10-05 21:10:01 -0400
commitdff8b887edf10407f22aaab9d147948cd5491f0a (patch)
tree14456ec6e2161ab1146e0bd9a2c9063fd56f87b4 /src/lib/ipc
parent81b2a927d50def6c2643db51394a170593d1db85 (diff)
New upstream version 2.3.2+dfsgupstream/2.3.2+dfsg
Diffstat (limited to 'src/lib/ipc')
-rw-r--r--src/lib/ipc/IpcClientProxy.cpp19
-rw-r--r--src/lib/ipc/IpcClientProxy.h6
-rw-r--r--src/lib/ipc/IpcLogOutputter.cpp14
-rw-r--r--src/lib/ipc/IpcLogOutputter.h5
-rw-r--r--src/lib/ipc/IpcServer.cpp33
-rw-r--r--src/lib/ipc/IpcServer.h3
6 files changed, 38 insertions, 42 deletions
diff --git a/src/lib/ipc/IpcClientProxy.cpp b/src/lib/ipc/IpcClientProxy.cpp
index af85eca..5104277 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<std::mutex> lock_read(m_readMutex);
+ std::lock_guard<std::mutex> 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<std::mutex> 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<std::mutex> 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 eaa12c7..eb9f1e9 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 <mutex>
+
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;
};
diff --git a/src/lib/ipc/IpcLogOutputter.cpp b/src/lib/ipc/IpcLogOutputter.cpp
index 984793e..b62c76a 100644
--- a/src/lib/ipc/IpcLogOutputter.cpp
+++ b/src/lib/ipc/IpcLogOutputter.cpp
@@ -39,7 +39,6 @@ enum EIpcLogOutputter {
IpcLogOutputter::IpcLogOutputter(IpcServer& ipcServer, EIpcClientType clientType, bool useThread) :
m_ipcServer(ipcServer),
- m_bufferMutex(ARCH->newMutex()),
m_sending(false),
m_bufferThread(nullptr),
m_running(false),
@@ -52,8 +51,7 @@ IpcLogOutputter::IpcLogOutputter(IpcServer& ipcServer, EIpcClientType clientType
m_bufferRateTimeLimit(kBufferRateTimeLimit),
m_bufferWriteCount(0),
m_bufferRateStart(ARCH->time()),
- m_clientType(clientType),
- m_runningMutex(ARCH->newMutex())
+ m_clientType(clientType)
{
if (useThread) {
m_bufferThread = new Thread(new TMethodJob<IpcLogOutputter>(
@@ -65,8 +63,6 @@ IpcLogOutputter::~IpcLogOutputter()
{
close();
- ARCH->closeMutex(m_bufferMutex);
-
if (m_bufferThread != nullptr) {
m_bufferThread->cancel();
m_bufferThread->wait();
@@ -86,7 +82,7 @@ void
IpcLogOutputter::close()
{
if (m_bufferThread != nullptr) {
- ArchMutexLock lock(m_runningMutex);
+ std::lock_guard<std::mutex> lock(m_runningMutex);
m_running = false;
notifyBuffer();
m_bufferThread->wait(5);
@@ -116,7 +112,7 @@ IpcLogOutputter::write(ELevel, const char* text)
void
IpcLogOutputter::appendBuffer(const String& text)
{
- ArchMutexLock lock(m_bufferMutex);
+ std::lock_guard<std::mutex> lock(m_bufferMutex);
double elapsed = ARCH->time() - m_bufferRateStart;
if (elapsed < m_bufferRateTimeLimit) {
@@ -143,7 +139,7 @@ IpcLogOutputter::appendBuffer(const String& text)
bool
IpcLogOutputter::isRunning()
{
- ArchMutexLock lock(m_runningMutex);
+ std::lock_guard<std::mutex> lock(m_runningMutex);
return m_running;
}
@@ -180,7 +176,7 @@ IpcLogOutputter::notifyBuffer()
String
IpcLogOutputter::getChunk(size_t count)
{
- ArchMutexLock lock(m_bufferMutex);
+ std::lock_guard<std::mutex> lock(m_bufferMutex);
if (m_buffer.size() < count) {
count = m_buffer.size();
diff --git a/src/lib/ipc/IpcLogOutputter.h b/src/lib/ipc/IpcLogOutputter.h
index 461f022..2f1b98c 100644
--- a/src/lib/ipc/IpcLogOutputter.h
+++ b/src/lib/ipc/IpcLogOutputter.h
@@ -24,6 +24,7 @@
#include "ipc/Ipc.h"
#include <deque>
+#include <mutex>
class IpcServer;
class Event;
@@ -100,7 +101,7 @@ private:
IpcServer& m_ipcServer;
Buffer m_buffer;
- ArchMutex m_bufferMutex;
+ std::mutex m_bufferMutex;
bool m_sending;
Thread* m_bufferThread;
bool m_running;
@@ -115,5 +116,5 @@ private:
UInt16 m_bufferWriteCount;
double m_bufferRateStart;
EIpcClientType m_clientType;
- ArchMutex m_runningMutex;
+ std::mutex m_runningMutex;
};
diff --git a/src/lib/ipc/IpcServer.cpp b/src/lib/ipc/IpcServer.cpp
index e05a913..8df98d1 100644
--- a/src/lib/ipc/IpcServer.cpp
+++ b/src/lib/ipc/IpcServer.cpp
@@ -56,7 +56,6 @@ IpcServer::init()
{
m_socket = new TCPListenSocket(m_events, m_socketMultiplexer, IArchNetwork::kINET);
- m_clientsMutex = ARCH->newMutex();
m_address.resolve();
m_events->adoptHandler(
@@ -75,15 +74,15 @@ IpcServer::~IpcServer()
delete m_socket;
}
- ARCH->lockMutex(m_clientsMutex);
- ClientList::iterator it;
- for (it = m_clients.begin(); it != m_clients.end(); it++) {
- deleteClient(*it);
+ {
+ std::lock_guard<std::mutex> lock(m_clientsMutex);
+ ClientList::iterator it;
+ for (it = m_clients.begin(); it != m_clients.end(); it++) {
+ deleteClient(*it);
+ }
+ m_clients.clear();
}
- m_clients.clear();
- ARCH->unlockMutex(m_clientsMutex);
- ARCH->closeMutex(m_clientsMutex);
-
+
m_events->removeHandler(m_events->forIListenSocket().connecting(), m_socket);
}
@@ -103,10 +102,12 @@ IpcServer::handleClientConnecting(const Event&, void*)
LOG((CLOG_DEBUG "accepted ipc client connection"));
- ARCH->lockMutex(m_clientsMutex);
- IpcClientProxy* proxy = new IpcClientProxy(*stream, m_events);
- m_clients.push_back(proxy);
- ARCH->unlockMutex(m_clientsMutex);
+ IpcClientProxy* proxy = nullptr;
+ {
+ std::lock_guard<std::mutex> lock(m_clientsMutex);
+ proxy = new IpcClientProxy(*stream, m_events);
+ m_clients.push_back(proxy);
+ }
m_events->adoptHandler(
m_events->forIpcClientProxy().disconnected(), proxy,
@@ -127,7 +128,7 @@ IpcServer::handleClientDisconnected(const Event& e, void*)
{
IpcClientProxy* proxy = static_cast<IpcClientProxy*>(e.getTarget());
- ArchMutexLock lock(m_clientsMutex);
+ std::lock_guard<std::mutex> lock(m_clientsMutex);
m_clients.remove(proxy);
deleteClient(proxy);
@@ -153,7 +154,7 @@ IpcServer::deleteClient(IpcClientProxy* proxy)
bool
IpcServer::hasClients(EIpcClientType clientType) const
{
- ArchMutexLock lock(m_clientsMutex);
+ std::lock_guard<std::mutex> lock(m_clientsMutex);
if (m_clients.empty()) {
return false;
@@ -175,7 +176,7 @@ IpcServer::hasClients(EIpcClientType clientType) const
void
IpcServer::send(const IpcMessage& message, EIpcClientType filterType)
{
- ArchMutexLock lock(m_clientsMutex);
+ std::lock_guard<std::mutex> lock(m_clientsMutex);
ClientList::iterator it;
for (it = m_clients.begin(); it != m_clients.end(); it++) {
diff --git a/src/lib/ipc/IpcServer.h b/src/lib/ipc/IpcServer.h
index d9bbe3e..179bad8 100644
--- a/src/lib/ipc/IpcServer.h
+++ b/src/lib/ipc/IpcServer.h
@@ -25,6 +25,7 @@
#include "base/EventTypes.h"
#include <list>
+#include <mutex>
class Event;
class IpcClientProxy;
@@ -79,7 +80,7 @@ private:
TCPListenSocket* m_socket;
NetworkAddress m_address;
ClientList m_clients;
- ArchMutex m_clientsMutex;
+ mutable std::mutex m_clientsMutex;
#ifdef TEST_ENV
public: