~ use local memory if no shared memory exists

This commit is contained in:
Julian Hinxlage 2019-11-12 19:05:33 +01:00
parent 7b2ddf9e0a
commit 5aa0a7862f

View File

@ -63,7 +63,17 @@ void writeSharedMemory(char *data, int size, int offset) {
} }
char *getSharedMemory() { char *getSharedMemory() {
constexpr bool useLocal = false; bool useLocal = false;
if(!useLocal){
int shmId = shmget(impl.sharedMemoryKey, NULL, 0);
if(shmId < 0) {
//no shared memory found
useLocal = true;
} else {
return (char *) shmat(shmId, NULL, 0);
}
}
if(useLocal) { if(useLocal) {
//using a local buffer for shared memory testing //using a local buffer for shared memory testing
@ -72,14 +82,6 @@ char *getSharedMemory() {
localSharedMemory.resize(impl.sharedMemorySize * 1024); localSharedMemory.resize(impl.sharedMemorySize * 1024);
} }
return &localSharedMemory[0]; return &localSharedMemory[0];
}else {
int shmId = shmget(impl.sharedMemoryKey, NULL, 0);
if(shmId < 0) {
// we could return -1, not sure if it will be useful to continue after there is no shm allocated for any reason
return nullptr;
} else {
return (char *) shmat(shmId, NULL, 0);
}
} }
} }