21 #include <boost/interprocess/managed_shared_memory.hpp> 22 #include <boost/interprocess/smart_ptr/shared_ptr.hpp> 24 #include "FairMQLogger.h" 37 void InitializeSegment(
const std::string& op,
const std::string& name,
const size_t size = 0)
43 if (op ==
"open_or_create")
45 fSegment =
new bipc::managed_shared_memory(bipc::open_or_create, name.c_str(), size);
47 else if (op ==
"create_only")
49 fSegment =
new bipc::managed_shared_memory(bipc::create_only, name.c_str(), size);
51 else if (op ==
"open_only")
60 fSegment =
new bipc::managed_shared_memory(bipc::open_only, name.c_str());
63 catch (bipc::interprocess_exception& ie)
67 LOG(error) <<
"Could not open shared memory after " << numTries <<
" attempts, exiting!";
72 LOG(debug) <<
"Could not open shared memory segment on try " << numTries <<
". Retrying in 1 second...";
73 LOG(debug) << ie.what();
75 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
83 LOG(error) <<
"Unknown operation when initializing shared memory segment: " << op;
86 catch (std::exception& e)
88 LOG(error) <<
"Exception during shared memory segment initialization: " << e.what() <<
", application will now exit";
94 LOG(info) <<
"Segment already initialized";
98 bipc::managed_shared_memory* Segment()
const 106 LOG(error) <<
"Segment not initialized";
116 bipc::managed_shared_memory* fSegment;
122 bipc::managed_shared_memory::handle_t fHandle;
Definition: ShmChunk.h:28