Ring Daemon 16.0.0
Loading...
Searching...
No Matches
shm_header.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifndef SHM_HEADER_H_
19#define SHM_HEADER_H_
20
21#include <cstdint>
22#include <semaphore.h>
23
24/* Implementation note: double-buffering
25 * Shared memory is divided in two regions, each representing one frame.
26 * First byte of each frame is guaranteed to be aligned on 16 bytes.
27 * One region is marked as readable: this region can be safely read.
28 * The other region is writeable: only the producer can use it.
29 */
30
32{
33 sem_t mutex; // lock it before any operations on these fields
34 sem_t frameGenMutex; // unlocked by producer when frameGen is modified
35 unsigned frameGen; // monotonically incremented when a producer changes readOffset
36 unsigned frameSize; // size in bytes of 1 frame
37 unsigned mapSize; // size to map if you need all the data
38 unsigned readOffset; // offset of readable frame in data
39 unsigned writeOffset; // offset of writable frame in data
40 uint8_t data[]; // the whole shared memory
41};
42
43#endif
unsigned writeOffset
Definition shm_header.h:39
uint8_t data[]
Definition shm_header.h:40
unsigned mapSize
Definition shm_header.h:37
sem_t mutex
Definition shm_header.h:33
unsigned frameGen
Definition shm_header.h:35
unsigned readOffset
Definition shm_header.h:38
sem_t frameGenMutex
Definition shm_header.h:34
unsigned frameSize
Definition shm_header.h:36