15 #ifndef FAIR_MQ_SHMEM_MANAGER_H_ 16 #define FAIR_MQ_SHMEM_MANAGER_H_ 21 #include <FairMQLogger.h> 22 #include <FairMQUnmanagedRegion.h> 24 #include <boost/interprocess/ipc/message_queue.hpp> 25 #include <boost/interprocess/managed_shared_memory.hpp> 26 #include <boost/interprocess/sync/named_condition.hpp> 27 #include <boost/interprocess/sync/named_mutex.hpp> 33 #include <unordered_map> 51 Manager(
const std::string&
id,
size_t size);
60 boost::interprocess::managed_shared_memory& Segment() {
return fSegment; }
61 boost::interprocess::managed_shared_memory& ManagementSegment() {
return fManagementSegment; }
63 static void StartMonitor(
const std::string&);
65 void Interrupt() { fInterrupted.store(
true); }
66 void Resume() { fInterrupted.store(
false); }
67 bool Interrupted() {
return fInterrupted.load(); }
69 int GetDeviceCounter();
70 int IncrementDeviceCounter();
71 int DecrementDeviceCounter();
73 std::pair<boost::interprocess::mapped_region*, uint64_t> CreateRegion(
const size_t size,
const int64_t userFlags, RegionCallback callback,
const std::string& path =
"",
int flags = 0);
74 Region* GetRegion(
const uint64_t
id);
75 Region* GetRegionUnsafe(
const uint64_t
id);
76 void RemoveRegion(
const uint64_t
id);
78 std::vector<fair::mq::RegionInfo> GetRegionInfo();
79 std::vector<fair::mq::RegionInfo> GetRegionInfoUnsafe();
80 void SubscribeToRegionEvents(RegionEventCallback callback);
81 void UnsubscribeFromRegionEvents();
82 void RegionEventsSubscription();
84 void RemoveSegments();
88 std::string fSegmentName;
89 std::string fManagementSegmentName;
90 boost::interprocess::managed_shared_memory fSegment;
91 boost::interprocess::managed_shared_memory fManagementSegment;
92 VoidAlloc fShmVoidAlloc;
93 boost::interprocess::named_mutex fShmMtx;
95 boost::interprocess::named_condition fRegionEventsCV;
96 std::thread fRegionEventThread;
97 std::atomic<bool> fRegionEventsSubscriptionActive;
98 std::function<void(fair::mq::RegionInfo)> fRegionEventCallback;
99 std::unordered_map<uint64_t, RegionEvent> fObservedRegionEvents;
102 Uint64RegionInfoMap* fRegionInfos;
103 std::unordered_map<uint64_t, std::unique_ptr<Region>> fRegions;
105 std::atomic<bool> fInterrupted;
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23