From 843348338a38defa96bd633342ece4ef17c7bbc4 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 8 Oct 2013 14:40:49 +0200 Subject: [PATCH] check if shmem segment exists --- DataStructures/SharedMemoryFactory.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/DataStructures/SharedMemoryFactory.h b/DataStructures/SharedMemoryFactory.h index d4d9770d1..a0de8e47e 100644 --- a/DataStructures/SharedMemoryFactory.h +++ b/DataStructures/SharedMemoryFactory.h @@ -108,7 +108,29 @@ public: } } + template + static bool RegionExists( + const boost::filesystem::path & lock_file, + const IdentifierT id + ) { + boost::interprocess::xsi_key key( lock_file.string().c_str(), id ); + return RegionExists(key); + } + private: + static bool RegionExists( const boost::interprocess::xsi_key &key ) { + bool result = true; + try { + boost::interprocess::xsi_shared_memory shm( + boost::interprocess::open_only, + key + ); + } catch(...) { + result = false; + } + return result; + } + static void RemoveSharedMemory( const boost::interprocess::xsi_key &key ) {