Dev/shm fix remove (#1279)
Some checks failed
Build on RHEL9 / build (push) Failing after 3m30s
Build on RHEL8 / build (push) Failing after 5m9s

* one doesnt need to open shared memory to call removesharedmemory, and calling hasMemoryvalid without opening will cause segfault (not used now, but could in the future)

* fix test on shm
This commit is contained in:
2025-08-25 16:20:19 +02:00
committed by GitHub
parent 9af571ea0e
commit 5b069d85a8
5 changed files with 36 additions and 20 deletions

View File

@@ -57,6 +57,8 @@ template <typename T> class SharedMemory {
name = constructSharedMemoryName(detectorId, moduleIndex, tag);
}
explicit SharedMemory(const std::string &shm_name) : name(shm_name) {}
// Disable copy, since we refer to a unique location
SharedMemory(const SharedMemory &) = delete;
SharedMemory &operator=(const SharedMemory &other) = delete;
@@ -81,8 +83,12 @@ template <typename T> class SharedMemory {
}
bool memoryHasValidFlag() const {
if (shared_struct == nullptr) {
throw SharedMemoryError(
"Shared memory not mapped. Cannot check validity.");
}
// CtbConfig did not have shmversion before, so exact value check
if constexpr (is_type<CtbConfig, T>()) {
// CtbConfig did not have shmversion before, so exact value check
if (shared_struct->shmversion == SHM_IS_VALID_CHECK_VERSION) {
return true;
}
@@ -99,11 +105,18 @@ template <typename T> class SharedMemory {
}
void invalidate() {
bool wasValid = true;
if (shared_struct == nullptr) {
wasValid = false;
openSharedMemory(false);
}
// also called by obsolete shm test structure (so check added)
if constexpr (has_bool_isValid<T>::value) {
if (memoryHasValidFlag())
shared_struct->isValid = false;
}
if (!wasValid)
unmapSharedMemory();
}
T *operator()() {