2019-10-29 15:24:57 +01:00
|
|
|
#include "internal.h"
|
2019-11-04 23:17:15 +01:00
|
|
|
#include <sys/shm.h>
|
|
|
|
Impl impl;
|
2019-10-29 15:24:57 +01:00
|
|
|
|
2019-11-04 23:17:15 +01:00
|
|
|
void *getSharedMemory(){
|
|
|
|
impl.sharedMemorySize = 8000;
|
2019-10-29 15:24:57 +01:00
|
|
|
|
2019-11-04 23:17:15 +01:00
|
|
|
auto id = shmget(impl.sharedMemoryKey, impl.sharedMemorySize, 0644 | IPC_CREAT);
|
|
|
|
if(id == -1){
|
|
|
|
//error
|
|
|
|
impl.sharedMemorySize = 0;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-10-29 15:24:57 +01:00
|
|
|
|
2019-11-04 23:17:15 +01:00
|
|
|
void *data = shmat(id, nullptr, 0);
|
|
|
|
if(data == (char*)(-1)){
|
|
|
|
//error
|
|
|
|
impl.sharedMemorySize = 0;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getSharedMemorySize(){
|
|
|
|
return impl.sharedMemorySize;
|
|
|
|
}
|