From 03d653c0bbf9cfad41cbe6b27d9a3d83d3192d22 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Fri, 9 Dec 2016 00:13:47 +0000 Subject: [PATCH] Fix removing shared memory segments in a multi-process setup --- .../datafacade/shared_memory_datafacade.hpp | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/include/engine/datafacade/shared_memory_datafacade.hpp b/include/engine/datafacade/shared_memory_datafacade.hpp index caa0bf812..72eb5b916 100644 --- a/include/engine/datafacade/shared_memory_datafacade.hpp +++ b/include/engine/datafacade/shared_memory_datafacade.hpp @@ -46,22 +46,27 @@ class SharedMemoryDataFacade : public ContiguousInternalMemoryDataFacadeBase // if this returns false this is still in use if (exclusive_lock.try_lock()) { - // Now check if this is still the newest dataset - const boost::interprocess::sharable_lock - lock(shared_barriers->current_regions_mutex); - - auto shared_regions = storage::makeSharedMemory(storage::CURRENT_REGIONS); - const auto current_timestamp = - static_cast(shared_regions->Ptr()); - - if (current_timestamp->timestamp == shared_timestamp) + if (storage::SharedMemory::RegionExists(data_region)) { - util::Log(logDEBUG) << "Retaining data with shared timestamp " << shared_timestamp; - } - else - { - storage::SharedMemory::Remove(data_region); - storage::SharedMemory::Remove(layout_region); + BOOST_ASSERT(storage::SharedMemory::RegionExists(layout_region)); + + // Now check if this is still the newest dataset + const boost::interprocess::sharable_lock + lock(shared_barriers->current_regions_mutex); + + auto shared_regions = storage::makeSharedMemory(storage::CURRENT_REGIONS); + const auto current_timestamp = + static_cast(shared_regions->Ptr()); + + if (current_timestamp->timestamp == shared_timestamp) + { + util::Log(logDEBUG) << "Retaining data with shared timestamp " << shared_timestamp; + } + else + { + storage::SharedMemory::Remove(data_region); + storage::SharedMemory::Remove(layout_region); + } } } }