mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-02-10 01:58:41 +01:00
Dev/shm fix remove (#1279)
* 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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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()() {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user