+ fixed SharedMemoryAccess (build errors)
This commit is contained in:
parent
255b05cd19
commit
9ce7b06c83
|
@ -2,25 +2,27 @@
|
|||
// Created by Cigerxwin Chaker on 05.11.19.
|
||||
//
|
||||
#include <iostream>
|
||||
#include <sys/_types.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
//#include "sharedMemory.h" /* header is important for the shmID. name could be different. maybe not needed cause: (shmget(memory_access_key, NULL, 0)) */
|
||||
#include <sys/sem.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue