46 size_t instanceIdHash,
const std::string& mapFileName,
const std::string& dataConsistencyKeyDescriptor =
"");
54 void read(uint64_t bar, uint64_t address, int32_t* data,
size_t sizeInBytes)
override;
55 void write(uint64_t bar, uint64_t address, int32_t
const* data,
size_t sizeInBytes)
override;
60 std::string address, std::map<std::string, std::string> parameters);
70 std::map<uint64_t, SharedMemoryVector*> _barContents;
73 std::map<uint64_t, size_t> _barSizesInBytes;
76 const char* SHARED_MEMORY_BAR_PREFIX =
"BAR_";
78 class InterruptDispatcherInterface;
82 class SharedMemoryManager {
86 SharedMemoryManager(
SharedDummyBackend&, std::size_t instanceIdHash,
const std::string&);
87 ~SharedMemoryManager();
99 std::pair<size_t, size_t> getInfoOnMemory();
105 static const size_t SHARED_MEMORY_CONST_OVERHEAD = 1000;
106 static const size_t SHARED_MEMORY_OVERHEAD_PER_VECTOR = 160;
108 const char* SHARED_MEMORY_PID_SET_NAME =
"PidSet";
109 const char* SHARED_MEMORY_REQUIRED_VERSION_NAME =
"RequiredVersion";
117 boost::interprocess::managed_shared_memory segment;
127 unsigned* requiredVersion{
nullptr};
129 size_t getRequiredMemoryWithOverhead();
137 bool checkPidSetConsistency();
140 std::vector<std::string> listNamedElements();
144 boost::interprocess::named_mutex interprocessMutex;
146 boost::movelib::unique_ptr<InterruptDispatcherInterface> intDispatcherIf;
150 std::unique_ptr<SharedMemoryManager> sharedMemoryManager;
153 void setupBarContents();
156 size_t getTotalRegisterSizeInBytes()
const;
158 static void checkSizeIsMultipleOfWordSize(
size_t sizeInBytes);
160 static std::string convertPathRelativeToDmapToAbs(std::string
const& mapfileName);
171 using SemId = std::uint32_t;
175 SemEntry() =
default;
176 boost::interprocess::interprocess_semaphore s{0};
184 struct InterruptEntry {
185 int _controllerId{0};
187 std::uint32_t _counter = 0;
192 static const int maxInterruptEntries = 1000;
206 using Sem = boost::interprocess::interprocess_semaphore;
208 ShmForSems() =
default;
209 ShmForSems(
const ShmForSems&) =
delete;
212 Sem* addSem(SemId semId);
213 bool removeSem(SemId semId);
215 void cleanup(
PidSet* pidSet);
219 void addInterrupt(uint32_t interruptNumber);
224 std::list<Sem*> findSems(uint32_t interruptNumber = {},
bool update =
false);
230 InterruptEntry interruptEntries[maxInterruptEntries];
233 struct InterruptDispatcherThread;
235 class InterruptDispatcherInterface {
241 InterruptDispatcherInterface(
SharedDummyBackend& backend, boost::interprocess::managed_shared_memory& shm,
242 boost::interprocess::named_mutex& shmMutex);
245 ~InterruptDispatcherInterface();
249 static void cleanupShm(boost::interprocess::managed_shared_memory& shm);
250 static void cleanupShm(boost::interprocess::managed_shared_memory& shm,
PidSet* pidSet);
253 void triggerInterrupt(uint32_t intNumber);
254 boost::interprocess::named_mutex& _shmMutex;
257 boost::movelib::unique_ptr<InterruptDispatcherThread> _dispatcherThread;
261 struct InterruptDispatcherThread {
263 explicit InterruptDispatcherThread(InterruptDispatcherInterface* dispatcherInterf);
264 InterruptDispatcherThread(
const InterruptDispatcherThread&) =
delete;
266 ~InterruptDispatcherThread();
269 void stop()
noexcept;
271 void handleInterrupt(uint32_t interruptNumber);
275 InterruptDispatcherInterface* _dispatcherInterf;
278 ShmForSems::Sem* _sem =
nullptr;
284 std::atomic_bool _started{
false};
285 std::atomic_bool _stop{
false};