From 84ddb4ba2188422ce6bb16835b3da194cb2abc74 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Sat, 30 Jun 2018 01:48:31 +0200 Subject: [PATCH] logic: Force unlock shared memory mutex of SharedMemoryGarbageCollector on creation --- src/lib/utility/interprocess/SharedMemory.cpp | 5 +++++ src/lib/utility/interprocess/SharedMemory.h | 4 +++- .../utility/interprocess/SharedMemoryGarbageCollector.cpp | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/utility/interprocess/SharedMemory.cpp b/src/lib/utility/interprocess/SharedMemory.cpp index f032b036..a8d9d398 100644 --- a/src/lib/utility/interprocess/SharedMemory.cpp +++ b/src/lib/utility/interprocess/SharedMemory.cpp @@ -163,6 +163,11 @@ SharedMemory::~SharedMemory() } } +void SharedMemory::unlockSharedMutex() +{ + getMutex().unlock(); +} + std::string SharedMemory::getMemoryName() const { return s_memoryNamePrefix + m_name; diff --git a/src/lib/utility/interprocess/SharedMemory.h b/src/lib/utility/interprocess/SharedMemory.h index a1fa3919..197c3975 100644 --- a/src/lib/utility/interprocess/SharedMemory.h +++ b/src/lib/utility/interprocess/SharedMemory.h @@ -40,7 +40,7 @@ public: template using Set = boost::interprocess::set, boost::interprocess::allocator>; - // Names addressing shared memory objects longer than 29 characters can throw and exception + // Names addressing shared memory objects longer than 29 characters can throw an exception static std::string checkName(const std::string& name); static std::string checkSharedMemory(const std::string& name); static void deleteSharedMemory(const std::string& name); @@ -99,6 +99,8 @@ public: std::string m_memoryName; }; + void unlockSharedMutex(); + private: static const char* s_memoryNamePrefix; static const char* s_mutexNamePrefix; diff --git a/src/lib/utility/interprocess/SharedMemoryGarbageCollector.cpp b/src/lib/utility/interprocess/SharedMemoryGarbageCollector.cpp index 192dbb40..588a8eb7 100644 --- a/src/lib/utility/interprocess/SharedMemoryGarbageCollector.cpp +++ b/src/lib/utility/interprocess/SharedMemoryGarbageCollector.cpp @@ -40,6 +40,7 @@ SharedMemoryGarbageCollector::SharedMemoryGarbageCollector() : m_memory(getMemoryName(), 65536 /* 64 kB */, SharedMemory::OPEN_OR_CREATE) , m_loopIsRunning(false) { + m_memory.unlockSharedMutex(); } SharedMemoryGarbageCollector::~SharedMemoryGarbageCollector()