shm (Shared Memory)ο
Header: udo/shm.h
Table of contents (click to go)ο
Macrosο
Enumsο
Unionsο
Structsο
Functionsο
API Documentationο
udo_shm_proc (private)ο
Structure defining the udo_shm_proc
(UDO Shared Memory Process) context.
-
struct udo_shm_procο
-
rd_fux- Pointer to a given process read futexstored in front segment of shared memory.
wr_fux- Pointer to a given process write futexstored in front segment of shared memory.
data- Pointer to an unsigned char storing locationwithin shared memory. This pointer is agiven processes shared memory segmentstaring address.
data_sz- Stores the size of a given processesshared memory segment.
udo_shm (private)ο
Structure defining the udo_shm
(UDO Shared Memory) context.
-
struct udo_shmο
-
struct udo_log_error_struct err;ο
-
bool free;ο
-
int fd;ο
-
char shm_file[SHM_FILE_NAME_MAX];ο
-
void *data;ο
-
size_t data_sz;ο
-
struct udo_shm_proc procs[SHM_PROC_MAX];ο
err- Stores information about the error that occuredfor the given context and may later be retrievedby caller.
freefd- Open file descriptor to POSIX shared memory.
shm_file- Name of the POSIX shared memory file starting with
'/'. data- Pointer to mmap(2) mapβd shared memory data.
data_sz- Total size of the shared memory region mapped with mmap(2).
procs- An array storing the shared memory locationsof each processes futexes and data.
-
struct udo_log_error_struct err;ο
udo_shm_create_infoο
Structure passed to
udo_shm_create() usedto define shared memory file name, shm size,
and process count.
-
struct udo_shm_create_infoο
-
shm_file- Shared memory file name. Must startwith the character
'/'. shm_size- Size of shared memory.
proc_count- Amount of processes able to read andwrite to and from the shared memoryblock.
Creates POSIX shared memory and futexes.
Each process gets:
1. Read futex (initialized to locked)
2. Write futex (initialized to unlocked)
3. Segment within shared memory to store data
Shared Memory Block (3 Processes)ο Data Stored
Offset In Bytes
Byte Size
Initial Value
Process Count
0
4
0
P1 Read Futex
4
4
1
P1 Write Futex
8
4
0
P2 Read Futex
12
4
1
P2 Write Futex
16
4
0
P3 Read Futex
20
4
1
P3 Write Futex
24
4
0
P1 Data Segment
28
Varies based upon
shm_size0
P2 Data Segment
Varies based upon
shm_sizeVaries based upon
shm_size0
P3 Data Segment
Varies based upon
shm_sizeVaries based upon
shm_size0
Param
Decription
shm
shm_info
Implementation uses a pointer to astructudo_shm_create_info.
- Returns:
on success: Pointer to astructudo_shmon failure:NULL
udo_shm_data_infoο
Structure defining what operations to perform
and data to retrieve during calls to
udo_shm_data_readο
Reads data stored in shared memory at
caller defined offset and writes into
a caller defined buffer.
Param
Decription
shm
Pointer to a validstructudo_shm.shm_info
Must pass a pointer to astructudo_shm_data_info.
- Returns:
on success: 0on failure: -1
udo_shm_data_writeο
Write data stored in caller defined buffer
into shared memory at a caller defined
shared memory offset.
Param
Decription
shm
Pointer to a validstructudo_shm.shm_info
Must pass a pointer to astructudo_shm_data_info.
- Returns:
on success: 0on failure: -1
udo_shm_get_fdο
Returns file descriptor to the POSIX shared memory
created after call to
udo_shm_create().
Param
Decription
shm
Pointer to a validstructudo_shm.
- Returns:
on success: File descriptor to POSIX shared memoryon failure: -1
udo_shm_get_dataο
Returns starting address of a processes segment
in the mmap(2) mapβd POSIX shared memory buffer
created after call to
udo_shm_create().
Param
Decription
shm
Pointer to a validstructudo_shm.proc_index
Process index to acquire itβs sharedmemory segment starting address.
- Returns:
on success: Pointer to processes SHM segmenton failure: NULL
udo_shm_get_data_sizeο
Returns size of a given process POSIX shared
memory segment size created after call to
Param
Decription
shm
Pointer to a validstructudo_shm.proc_index
Process index to acquire itβs sharedmemory segment starting address.
- Returns:
on success: Size of processes SHM segmenton failure: (size_t)-1
udo_shm_destroyο
Frees any allocated memory and closes FDβs (if open) created after
udo_shm_create() call.
Param
Decription
shm
Pointer to a validstructudo_shm.
udo_shm_get_sizeofο
-
int udo_shm_get_sizeof(void);ο
Returns size of the internal structure. So,
if caller decides to allocate memory outside
of API interface they know the exact amount
of bytes.