getShareMemory(char *address, int size, int offset) hinzufuegen, ob man es braucht.
This commit is contained in:
parent
70ac303036
commit
f9c866231b
@ -61,10 +61,27 @@ void writeSharedMemory(char *data, int size, int offset) {
|
||||
return;
|
||||
/* we could return -1, not sure if it will be useful to continue after there is no shm allocated for any reason*/
|
||||
} else {
|
||||
std::cout << "writing" << std::endl;
|
||||
char *shm_pointer = (char *) shmat(shmId, NULL, 0);
|
||||
semaphoreOperation(LOCK);
|
||||
memcpy(shm_pointer + offset, data, size);
|
||||
shmdt(shm_pointer); //close shm_pointer
|
||||
semaphoreOperation(UNLOCK);
|
||||
std::cout << "writing successed" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void getSharedMemory(char *address, int size, int offset) {
|
||||
int shmId = shmget(impl.sharedMemoryKey, NULL, 0);
|
||||
if(shmId < 0) {
|
||||
return;
|
||||
} else {
|
||||
char *shm_pointer = (char *) shmat(shmId, NULL, 0);
|
||||
semaphoreOperation(LOCK);
|
||||
memcpy(address, shm_pointer + offset, size);
|
||||
shmdt(shm_pointer); //close shm_pointer
|
||||
semaphoreOperation(UNLOCK);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,15 @@
|
||||
*/
|
||||
char *getSharedMemory();
|
||||
|
||||
/**
|
||||
* use lock and unlock when writing,
|
||||
* set content to the address
|
||||
* @param *address target address
|
||||
* @param size of data
|
||||
* @param offset where the data is written on the shared memory
|
||||
*/
|
||||
void getSharedMemory(char *address, int size, int offset);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the size of the shared memory
|
||||
@ -24,10 +33,10 @@ void unlockSharedMemory();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data poiter to data
|
||||
* @param data pointer to data
|
||||
* @param size of data
|
||||
* @param offset where the data is written on the shared memory
|
||||
*/
|
||||
void writeSharedMemory(char *data, int size, int offset);
|
||||
void writeSharedMemory(char *date, int size, int offset);
|
||||
|
||||
#endif //LIBRARY_SHAREDMEMORYACCESSS_H
|
||||
|
Loading…
Reference in New Issue
Block a user