30 #include <boost/interprocess/managed_shared_memory.hpp>
31 #include <boost/interprocess/sync/interprocess_upgradable_mutex.hpp>
32 #include <boost/interprocess/sync/sharable_lock.hpp>
39 #include <ArmarXCore/interface/core/SharedMemory.h>
44 boost::interprocess::sharable_lock<boost::interprocess::interprocess_upgradable_mutex>;
54 template <
class MemoryObject,
class MemoryObjectMetaInfo = MetaInfoSizeBase>
58 class Wrapper :
public MemoryObjectMetaInfo
80 this->memoryName = newMemoryName;
81 auto env_c_str = getenv(
"USER");
82 std::string userName = env_c_str ? env_c_str :
"";
84 if (!userName.empty())
86 this->memoryName += userName;
92 sharedMemorySegment =
new boost::interprocess::managed_shared_memory(
93 boost::interprocess::open_only, memoryName.c_str());
95 catch (
const boost::interprocess::interprocess_exception& e)
97 std::string reason =
"Error opening shared memory segment for reading: ";
102 info = sharedMemorySegment->find<
Wrapper>(
"Info").first;
107 memoryName,
"Error opening memory size for reading");
113 ->find<boost::interprocess::interprocess_upgradable_mutex>(
"SharedMutex")
119 memoryName,
"Error opening shared mutex for reading");
123 data = sharedMemorySegment->find<MemoryObject>(
"Data").first;
128 memoryName,
"Error opening shared data for reading");
133 ->find<boost::interprocess::interprocess_condition>(
"CondSizeChanged")
139 memoryName,
"Error opening condition variable for reading");
164 memoryName,
"Error opening shared mutex for reading");
170 typename MemoryObjectMetaInfo::PointerType
225 memoryMutex->lock_sharable();
237 memoryMutex->unlock_sharable();
245 std::shared_ptr<SharedMemoryConsumer<MemoryObject, MemoryObjectMetaInfo>>;
251 std::string memoryName;
256 boost::interprocess::managed_shared_memory* sharedMemorySegment;
261 mutable boost::interprocess::interprocess_upgradable_mutex* memoryMutex;
266 boost::interprocess::interprocess_condition* condSizeChanged;
273 MemoryObjectMetaInfo* info;