+ getSharedMemory cleanup

This commit is contained in:
Julian Hinxlage 2019-11-07 12:41:01 +01:00
parent 9e38b13792
commit 9d0766612f
2 changed files with 4 additions and 24 deletions

View File

@ -2,32 +2,10 @@
#include <sys/shm.h>
#include <csignal>
#include "SharedMemoryAccess.h"
Impl impl;
void *getSharedMemory(){
impl.sharedMemorySize = 8000;
auto id = shmget(impl.sharedMemoryKey, impl.sharedMemorySize, 0644u | IPC_CREAT);
if(id == -1){
//error
impl.sharedMemorySize = 0;
return nullptr;
}
void *data = shmat(id, nullptr, 0);
if(data == (char*)(-1)){
//error
impl.sharedMemorySize = 0;
return nullptr;
}
return data;
}
int getSharedMemorySize(){
return impl.sharedMemorySize;
}
void sendSignal(pid_t pid, int signalNumber) {
kill(pid, signalNumber);
}

View File

@ -16,6 +16,8 @@ bool registerEvent(EventType type, std::function<void()> handler) {
ivt[type].pid = getpid();
ivt[type].signum = signum;
impl.eventTable.push_back(handler);
onSignal(signum, [](int sig){
if(sig >= SIGUSR1){
if((sig - SIGUSR1) < impl.eventTable.size()){