From 9eff30845b14f51ffa0a38839288522796b85380 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Mon, 6 Apr 2020 19:42:30 +0200 Subject: WIP: comments Change-Id: Ia2631a869e23af520b9eade192dfdb032174c689 --- Transceiver52M/device/ipc/shm.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) 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 +#include // For mode constants +#include // For O_* constants +#include + +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 #include #include -- cgit v1.2.3-59-g8ed1b