From 9ce7b06c83ca4b6db12dbbd136639d150e61f40c Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Wed, 6 Nov 2019 11:54:26 +0100 Subject: [PATCH] + fixed SharedMemoryAccess (build errors) --- src/SharedMemoryAccess.cpp | 14 ++++++++------ src/SharedMemoryAccess.h | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/SharedMemoryAccess.cpp b/src/SharedMemoryAccess.cpp index e5e4543..9f13ff9 100644 --- a/src/SharedMemoryAccess.cpp +++ b/src/SharedMemoryAccess.cpp @@ -2,25 +2,27 @@ // Created by Cigerxwin Chaker on 05.11.19. // #include -#include +#include #include #include #include #include #include -//#include "sharedMemory.h" /* header is important for the shmID. name could be different. maybe not needed cause: (shmget(memory_access_key, NULL, 0)) */ #include #include +#include + +#include "SharedMemoryAccess.h" /* header is important for the shmID. name could be different. maybe not needed cause: (shmget(memory_access_key, NULL, 0)) */ int initSemaphore (void) { /* Testen, ob das Semaphor bereits existiert */ - semId = semget (semKey, 0, IPC_PRIVATE); + semId = semget (SEM_KEY, 0, IPC_PRIVATE); if (semId < 0) { /* ... existiert noch nicht, also anlegen */ /* Alle Zugriffsrechte der Dateikreierungsmaske */ /* erlauben */ umask(0); - semId = semget (semKey, 1, IPC_CREAT | IPC_EXCL | PERM); + semId = semget (SEM_KEY, 1, IPC_CREAT | IPC_EXCL | PERM); if (semId < 0) { return -1; } @@ -48,9 +50,9 @@ void writeToShm(char* text, int size) { /* we could return -1, not sure if it will be useful to continue after there is no shm allocated for any reason*/ } else { char *shm_pointer = (char *) shmat(shmId, NULL, 0); - semaphore_operation(LOCK); + semaphoreOperation(LOCK); memcpy(shm_pointer, text, size); - semaphore_operation(UNLOCK); + semaphoreOperation(UNLOCK); } } diff --git a/src/SharedMemoryAccess.h b/src/SharedMemoryAccess.h index 9f26857..d9e15bf 100644 --- a/src/SharedMemoryAccess.h +++ b/src/SharedMemoryAccess.h @@ -8,7 +8,7 @@ #define PERM 0666 /* Zugriffsrechte */ #define LOCK -1 #define UNLOCK 1 -#define SemKey 123458L +#define SEM_KEY 123458L int memoryAccessKey; /* var type is int. but could be another type. */ //TODO: look after type in sharedmemory group int semId; @@ -17,4 +17,5 @@ int initSemaphore (void); int semaphoreOperation (int op); char* getShmPointer(void); void writeToShm(char* text, int size); + #endif //LIBRARY_SHAREDMEMORYACCESSS_H