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

@@ -29,7 +29,6 @@ void freeSharedMemory(const int detectorIndex, const int moduleIndex) {
if (moduleIndex >= 0) {
SharedMemory<sharedModule> moduleShm(detectorIndex, moduleIndex);
if (moduleShm.exists()) {
moduleShm.openSharedMemory(false);
moduleShm.removeSharedMemory();
}
return;
@@ -48,7 +47,6 @@ void freeSharedMemory(const int detectorIndex, const int moduleIndex) {
for (int i = 0; i < numDetectors; ++i) {
SharedMemory<sharedModule> moduleShm(detectorIndex, i);
if (moduleShm.exists()) {
moduleShm.openSharedMemory(false);
moduleShm.removeSharedMemory();
}
}
@@ -56,7 +54,6 @@ void freeSharedMemory(const int detectorIndex, const int moduleIndex) {
// Ctb configuration
SharedMemory<CtbConfig> ctbShm(detectorIndex, -1, CtbConfig::shm_tag());
if (ctbShm.exists()) {
ctbShm.openSharedMemory(false);
ctbShm.removeSharedMemory();
}
}

View File

@@ -3396,11 +3396,11 @@ void Module::createSharedMemory(detectorType type, int det_id) {
// ensure shared memory was not created before
if (shm.exists()) {
throw SharedMemoryError(
"This shared memory " + shm.getName() +
" should have been deleted before! Free it to continue.");
LOG(logWARNING)
<< "This shared memory " + shm.getName() +
" should have been deleted before! Freeing it to continue.";
shm.removeSharedMemory();
}
shm.createSharedMemory();
initializeModuleStructure(type);
}

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()() {

View File

@@ -33,7 +33,6 @@ struct ObsoleteCtbData {
void freeShm(const int dindex, const int mIndex) {
SharedMemory<Data> shm(dindex, mIndex);
if (shm.exists()) {
shm.openSharedMemory(false);
shm.removeSharedMemory();
}
}