diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2020-04-06 19:42:30 +0200 |
---|---|---|
committer | Eric <ewild@sysmocom.de> | 2020-08-26 17:35:18 +0200 |
commit | b49c8ab965e8bad822a05eaa51fb6b7491e3100b (patch) | |
tree | b1c9d30320d17cccd5658642a5a31bbc5948c81c | |
parent | d5ff10069cc6c8dce0d341e109a4a6614ab0b2d3 (diff) |
WIP: comments
Change-Id: Ia2631a869e23af520b9eade192dfdb032174c689
-rw-r--r-- | Transceiver52M/device/ipc/shm.h | 41 |
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> |