aboutsummaryrefslogtreecommitdiffstats
path: root/Transceiver52M/device
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2020-04-06 19:42:30 +0200
committerEric <ewild@sysmocom.de>2020-04-15 22:43:15 +0200
commit87a77440f268fd8de41f5c0e2cf5b8cf1d05f97f (patch)
tree47928ddf659e83d9bb6fcab98a1387cea3656635 /Transceiver52M/device
parent87d6f3c8e1d0fc9d39520f7f2d25552d497c883b (diff)
WIP: comments
Diffstat (limited to 'Transceiver52M/device')
-rw-r--r--Transceiver52M/device/ipc/shm.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/Transceiver52M/device/ipc/shm.h b/Transceiver52M/device/ipc/shm.h
index 8ee35d2..0ad0fd9 100644
--- a/Transceiver52M/device/ipc/shm.h
+++ b/Transceiver52M/device/ipc/shm.h
@@ -16,6 +16,47 @@
*/
+/*
+https://www.softprayog.in/programming/interprocess-communication-using-posix-shared-memory-in-linux
+
+man shm_open: link with -lrt
+Link with -pthread.
+
+#include <sys/mman.h>
+#include <sys/stat.h> // For mode constants
+#include <fcntl.h> // For O_* constants
+#include <semaphore.h>
+
+On start:
+int fd = shm_open(const char *name, int oflag, mode_t mode);
+* name must start with "/" and not contain more slashes.
+* name must be a null-terminted string of up to NAME_MAX (255)
+* oflag: O_CREAT|O_RDWR|O_EXCL
+* mode: check man open
+
+ftruncate(fd, len = sizeof(struct myshamemorystruct) to expand the memory region
+
+shm = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+
+int sem_init(sem_t *&(shm->sem), 1, unsigned int value) == 0;
+
+close(fd); // After a call to mmap(2) the file descriptor may be closed without affecting the memory mapping.
+
+
+On exit:
+int shm_unlink(const char *name);
+
+
+sem_t *sem_open(const char *name, int oflag,
+ mode_t mode, unsigned int value);
+* by a name of the form /somename; that is, a null-terminated string of up to NAME_MAX-4 (i.e., 251) characters
+ consisting of an initial slash, followed by one or more characters, none of which are slashes.
+
+
+* unamed semaphore: sem_init + sem_destroy
+* Programs using the POSIX semaphores API must be compiled with cc -pthread to link against the real-time library, librt
+*/
+
#include <stdint.h>
#include <unistd.h>
#include <limits.h>