50 size_t instanceIdHash,
const std::string& mapFileName,
const std::string& dataConsistencyKeyDescriptor =
"");
58 void read(uint64_t bar, uint64_t address, int32_t* data,
size_t sizeInBytes)
override;
59 void write(uint64_t bar, uint64_t address, int32_t
const* data,
size_t sizeInBytes)
override;
64 std::string address, std::map<std::string, std::string> parameters);
74 std::map<uint64_t, SharedMemoryVector*> _barContents;
77 std::map<uint64_t, size_t> _barSizesInBytes;
80 const char* SHARED_MEMORY_BAR_PREFIX =
"BAR_";
82 class InterruptDispatcherInterface;
86 class SharedMemoryManager {
90 SharedMemoryManager(
SharedDummyBackend&, std::size_t instanceIdHash,
const std::string&);
91 ~SharedMemoryManager();
103 std::pair<size_t, size_t> getInfoOnMemory();
109 static const size_t SHARED_MEMORY_CONST_OVERHEAD = 1000;
110 static const size_t SHARED_MEMORY_OVERHEAD_PER_VECTOR = 160;
112 const char* SHARED_MEMORY_PID_SET_NAME =
"PidSet";
113 const char* SHARED_MEMORY_REQUIRED_VERSION_NAME =
"RequiredVersion";
121 boost::interprocess::managed_shared_memory segment;
131 unsigned* requiredVersion{
nullptr};
133 size_t getRequiredMemoryWithOverhead();
141 bool checkPidSetConsistency();
144 std::vector<std::string> listNamedElements();
148 boost::interprocess::named_mutex interprocessMutex;
150 boost::movelib::unique_ptr<InterruptDispatcherInterface> intDispatcherIf;
154 std::unique_ptr<SharedMemoryManager> sharedMemoryManager;
157 void setupBarContents();
160 size_t getTotalRegisterSizeInBytes()
const;
162 static void checkSizeIsMultipleOfWordSize(
size_t sizeInBytes);
164 static std::string convertPathRelativeToDmapToAbs(std::string
const& mapfileName);
175 using SemId = std::uint32_t;
179 SemEntry() =
default;
180 boost::interprocess::interprocess_semaphore s{0};
188 struct InterruptEntry {
189 int _controllerId{0};
191 std::uint32_t _counter = 0;
196 static const int maxInterruptEntries = 1000;
210 using Sem = boost::interprocess::interprocess_semaphore;
212 ShmForSems() =
default;
213 ShmForSems(
const ShmForSems&) =
delete;
216 Sem* addSem(SemId semId);
217 bool removeSem(SemId semId);
219 void cleanup(
PidSet* pidSet);
223 void addInterrupt(uint32_t interruptNumber);
228 std::list<Sem*> findSems(uint32_t interruptNumber = {},
bool update =
false);
234 InterruptEntry interruptEntries[maxInterruptEntries];
237 struct InterruptDispatcherThread;
239 class InterruptDispatcherInterface {
245 InterruptDispatcherInterface(
SharedDummyBackend& backend, boost::interprocess::managed_shared_memory& shm,
246 boost::interprocess::named_mutex& shmMutex);
249 ~InterruptDispatcherInterface();
253 static void cleanupShm(boost::interprocess::managed_shared_memory& shm);
254 static void cleanupShm(boost::interprocess::managed_shared_memory& shm,
PidSet* pidSet);
257 void triggerInterrupt(uint32_t intNumber);
258 boost::interprocess::named_mutex& _shmMutex;
261 boost::movelib::unique_ptr<InterruptDispatcherThread> _dispatcherThread;
265 struct InterruptDispatcherThread {
267 explicit InterruptDispatcherThread(InterruptDispatcherInterface* dispatcherInterf);
268 InterruptDispatcherThread(
const InterruptDispatcherThread&) =
delete;
270 ~InterruptDispatcherThread();
273 void stop()
noexcept;
275 void handleInterrupt(uint32_t interruptNumber);
279 InterruptDispatcherInterface* _dispatcherInterf;
282 ShmForSems::Sem* _sem =
nullptr;
284 std::atomic_bool _started{
false};
285 std::atomic_bool _stop{
false};