Dev/shm free obsolete (#1274)
Some checks failed
Build on RHEL9 / build (push) Failing after 3m24s
Build on RHEL8 / build (push) Failing after 5m7s

* freeing obsolete shm withoua a 'isValid' should access raw pointers. Need to move this all into the shm class

* fixed obsolete shm free issue

* minor

* ensuring the test works platform independent for size of int
This commit is contained in:
2025-08-21 14:32:15 +02:00
committed by GitHub
parent 72056ff813
commit 15cbaa509e
7 changed files with 139 additions and 33 deletions

View File

@@ -27,17 +27,25 @@
namespace sls {
struct sharedDetector;
struct CtbConfig;
// struct sharedDetector;
#define SHM_DETECTOR_PREFIX "/slsDetectorPackage_detector_"
#define SHM_MODULE_PREFIX "_module_"
#define SHM_ENV_NAME "SLSDETNAME"
#define SHM_IS_VALID_CHECK_VERSION 0x250820
#define SHM_DETECTOR_PREFIX "/slsDetectorPackage_detector_"
#define SHM_MODULE_PREFIX "_module_"
#define SHM_ENV_NAME "SLSDETNAME"
template <typename T, typename U> constexpr bool is_type() {
return std::is_same_v<std::decay_t<U>, T>;
}
template <typename T> class SharedMemory {
#ifndef DISABLE_STATIC_ASSERT
static_assert(has_bool_isValid<T>::value,
"SharedMemory requires the struct to have a bool member "
"named 'isValid'");
#endif
static constexpr int NAME_MAX_LENGTH = 255;
std::string name;
@@ -72,21 +80,49 @@ template <typename T> class SharedMemory {
unmapSharedMemory();
}
bool memoryHasValidFlag() const {
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;
}
} else if (shared_struct->shmversion >= SHM_IS_VALID_CHECK_VERSION) {
return true;
}
return false;
}
bool checkValidity() const {
if (memoryHasValidFlag() && !shared_struct->isValid)
return false;
return true;
}
void invalidate() {
// also called by obsolete shm test structure (so check added)
if constexpr (has_bool_isValid<T>::value) {
if (memoryHasValidFlag())
shared_struct->isValid = false;
}
}
T *operator()() {
if (!shared_struct)
throw SharedMemoryError(getNoShmAccessMessage());
if (!shared_struct->isValid) {
if (!checkValidity())
throw SharedMemoryError(getInvalidShmMessage());
}
return shared_struct;
}
const T *operator()() const {
if (!shared_struct)
throw SharedMemoryError(getNoShmAccessMessage());
if (!shared_struct->isValid) {
if (!checkValidity())
throw SharedMemoryError(getInvalidShmMessage());
}
return shared_struct;
}
@@ -146,6 +182,7 @@ template <typename T> class SharedMemory {
}
void removeSharedMemory() {
invalidate();
unmapSharedMemory();
if (shm_unlink(name.c_str()) < 0) {
// silent exit if shm did not exist anyway