+ getSharedMemory cleanup
This commit is contained in:
parent
9e38b13792
commit
9d0766612f
@ -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);
|
||||
}
|
||||
|
@ -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()){
|
||||
|
Loading…
Reference in New Issue
Block a user