slsDetectorSoftware: Sharedmemory removed private methodf or removeshm, removed static isexisting as the usecases are all member method

This commit is contained in:
2018-07-06 15:18:34 +02:00
parent 7c29327b47
commit ecd0c810ca
4 changed files with 22 additions and 30 deletions

View File

@@ -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());
}