mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-17 09:29:55 +01:00
slsDetectorSoftware: Sharedmemory removed private methodf or removeshm, removed static isexisting as the usecases are all member method
This commit is contained in:
@@ -28,13 +28,13 @@ SharedMemory::~SharedMemory(){
|
||||
}
|
||||
|
||||
|
||||
bool SharedMemory::IsExisting(std::string name) {
|
||||
bool SharedMemory::IsExisting() {
|
||||
bool ret = true;
|
||||
int fd = shm_open(name.c_str(), O_RDWR, 0);
|
||||
if ((fd < 0) && (errno == ENOENT)) {
|
||||
int tempfd = shm_open(name.c_str(), O_RDWR, 0);
|
||||
if ((tempfd < 0) && (errno == ENOENT)) {
|
||||
ret = false;
|
||||
}
|
||||
close(fd);
|
||||
close(tempfd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,9 @@ void* SharedMemory::CreateSharedMemory(size_t sz){
|
||||
}
|
||||
|
||||
// map
|
||||
return MapSharedMemory(sz);
|
||||
void* addr = MapSharedMemory(sz);
|
||||
printf("Shared memory created %s \n", name.c_str());
|
||||
return addr;
|
||||
}
|
||||
|
||||
void* SharedMemory::OpenSharedMemory(size_t sz){
|
||||
@@ -87,7 +89,15 @@ void SharedMemory::UnmapSharedMemory(void* addr) {
|
||||
}
|
||||
|
||||
void SharedMemory::RemoveSharedMemory() {
|
||||
RemoveSharedMemory(name.c_str());
|
||||
if (shm_unlink(name.c_str()) < 0) {
|
||||
// silent exit if shm did not exist anyway
|
||||
if (errno == ENOENT)
|
||||
return;
|
||||
cprintf(RED, "Error: Free Shared Memory %s Failed: %s\n",
|
||||
name.c_str(), strerror(errno));
|
||||
throw SharedMemoryException();
|
||||
}
|
||||
printf("Shared memory deleted %s \n", name.c_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -146,15 +156,3 @@ int SharedMemory::VerifySizeMatch(size_t expectedSize) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SharedMemory::RemoveSharedMemory(std::string name) {
|
||||
if (shm_unlink(name.c_str()) < 0) {
|
||||
// silent exit if shm did not exist anyway
|
||||
if (errno == ENOENT)
|
||||
return;
|
||||
cprintf(RED, "Error: Free Shared Memory %s Failed: %s\n",
|
||||
name.c_str(), strerror(errno));
|
||||
throw SharedMemoryException();
|
||||
}
|
||||
printf("Shared memory deleted %s \n", name.c_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
* @param name of shared memory
|
||||
* @return true if exists, else false
|
||||
*/
|
||||
static bool IsExisting(std::string name);
|
||||
bool IsExisting();
|
||||
|
||||
/**
|
||||
* Get shared memory name
|
||||
@@ -93,12 +93,6 @@ private:
|
||||
*/
|
||||
int VerifySizeMatch(size_t expectedSize);
|
||||
|
||||
/**
|
||||
* Remove existing Shared memory
|
||||
* @param name name of shared memory (should be less than NAME_MAX)
|
||||
*/
|
||||
void RemoveSharedMemory(std::string name);
|
||||
|
||||
/** Shared memory name */
|
||||
std::string name;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user