30 #include <boost/interprocess/managed_shared_memory.hpp>
31 #include <boost/interprocess/sync/sharable_lock.hpp>
32 #include <boost/interprocess/sync/interprocess_upgradable_mutex.hpp>
37 #include <ArmarXCore/interface/core/SharedMemory.h>
52 template <
class MemoryObject,
class MemoryObjectMetaInfo = MetaInfoSizeBase>
59 class Wrapper :
public MemoryObjectMetaInfo
77 this->memoryName = newMemoryName;
78 auto env_c_str = getenv(
"USER");
79 std::string userName = env_c_str ? env_c_str :
"";
81 if (!userName.empty())
83 this->memoryName += userName;
89 sharedMemorySegment =
new boost::interprocess::managed_shared_memory(boost::interprocess::open_only, memoryName.c_str());
91 catch (
const boost::interprocess::interprocess_exception& e)
93 std::string reason =
"Error opening shared memory segment for reading: ";
97 info = sharedMemorySegment->find<
Wrapper>(
"Info").first;
105 memoryMutex = sharedMemorySegment->find<boost::interprocess::interprocess_upgradable_mutex>(
"SharedMutex").first;
113 data = sharedMemorySegment->find<MemoryObject>(
"Data").first;
120 condSizeChanged = sharedMemorySegment->find<boost::interprocess::interprocess_condition>(
"CondSizeChanged").first;
153 typename MemoryObjectMetaInfo::PointerType
getMetaInfo(
bool threadSafe =
true)
const
205 memoryMutex->lock_sharable();
216 memoryMutex->unlock_sharable();
223 using pointer_type = std::shared_ptr<SharedMemoryConsumer<MemoryObject, MemoryObjectMetaInfo> >;
229 std::string memoryName;
234 boost::interprocess::managed_shared_memory* sharedMemorySegment;
239 mutable boost::interprocess::interprocess_upgradable_mutex* memoryMutex;
244 boost::interprocess::interprocess_condition* condSizeChanged;
251 MemoryObjectMetaInfo* info;