L4Re - L4 Runtime Environment
Shared Memory Library

L4SHM provides a shared memory infrastructure that establishes a shared memory area between multiple parties and uses a fast notification mechanism. More...

+ Collaboration diagram for Shared Memory Library:

Modules

 Chunks
 
 Signals
 

Functions

long l4shmc_create (const char *shmc_name, l4_umword_t shm_size)
 Create a shared memory area. More...
 
long l4shmc_attach (const char *shmc_name, l4shmc_area_t *shmarea)
 Attach to a shared memory area. More...
 
long l4shmc_attach_to (const char *shmc_name, l4_umword_t timeout_ms, l4shmc_area_t *shmarea)
 Attach to a shared memory area, with limited waiting. More...
 
long l4shmc_connect_chunk_signal (l4shmc_chunk_t *chunk, l4shmc_signal_t *signal)
 Connect a signal with a chunk. More...
 
long l4shmc_area_size (l4shmc_area_t *shmarea)
 Get size of shared memory area. More...
 
long l4shmc_area_size_free (l4shmc_area_t *shmarea)
 Get free size of shared memory area. More...
 
long l4shmc_area_overhead (void)
 Get memory overhead per area that is not available for chunks. More...
 
long l4shmc_chunk_overhead (void)
 Get memory overhead required in addition to the chunk capacity for adding one chunk. More...
 

Detailed Description

L4SHM provides a shared memory infrastructure that establishes a shared memory area between multiple parties and uses a fast notification mechanism.

A shared memory area consists of chunks and signals. A chunk is a defined chunk of memory within the memory area with a maximum size. A chunk is filled (written) by a producer and read by a consumer. When a producer has finished writing to the chunk it signals a data ready notification to the consumer.

A consumer attaches to a chunk and waits for the producer to fill the chunk. After reading out the chunk it marks the chunk free again.

A shared memory area can have multiple chunks.

The interface is divided in three roles.

A signal can be connected with a chunk or can be used independently (e.g. for multiple chunks).

Function Documentation

◆ l4shmc_area_overhead()

long l4shmc_area_overhead ( void  )

Get memory overhead per area that is not available for chunks.

Returns
size of the overhead in bytes

◆ l4shmc_area_size()

long l4shmc_area_size ( l4shmc_area_t *  shmarea)
inline

Get size of shared memory area.

Parameters
shmareaShared memory area.
Return values
>0Size of the shared memory area.
<0Error.

◆ l4shmc_area_size_free()

long l4shmc_area_size_free ( l4shmc_area_t *  shmarea)

Get free size of shared memory area.

To get the max size to pass to l4shmc_add_chunk, substract l4shmc_chunk_overhead().

Parameters
shmareaShared memory area.
Return values
0Free capacity in the area.
<0Error.

◆ l4shmc_attach()

long l4shmc_attach ( const char *  shmc_name,
l4shmc_area_t *  shmarea 
)
inline

Attach to a shared memory area.

Parameters
shmc_nameName of the shared memory area.
[out]shmareaPointer to shared memory area descriptor to be filled with information for the shared memory area.
Return values
0Success.
<0Error.
Examples:
examples/libs/shmc/prodcons.c.

◆ l4shmc_attach_to()

long l4shmc_attach_to ( const char *  shmc_name,
l4_umword_t  timeout_ms,
l4shmc_area_t *  shmarea 
)

Attach to a shared memory area, with limited waiting.

Parameters
shmc_nameName of the shared memory area.
timeout_msTimeout to wait for shm area in milliseconds.
[out]shmareaPointer to shared memory area descriptor to be filled with information for the shared memory area.
Return values
0Success.
<0Error.

◆ l4shmc_chunk_overhead()

long l4shmc_chunk_overhead ( void  )

Get memory overhead required in addition to the chunk capacity for adding one chunk.

Returns
size of the overhead in bytes

◆ l4shmc_connect_chunk_signal()

long l4shmc_connect_chunk_signal ( l4shmc_chunk_t *  chunk,
l4shmc_signal_t *  signal 
)

Connect a signal with a chunk.

Parameters
chunkChunk to attach the signal to.
signalSignal to attach.
Returns
0 on success, <0 on error
Examples:
examples/libs/shmc/prodcons.c.

◆ l4shmc_create()

long l4shmc_create ( const char *  shmc_name,
l4_umword_t  shm_size 
)

Create a shared memory area.

Parameters
shmc_nameName of the shared memory area.
shm_sizeSize of the whole shared memory area.
Return values
0Success.
<0Error.
Examples:
examples/libs/shmc/prodcons.c.