Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
Static Memory Reservation

Fixed-size memory pools reserved at initialization (ADR-001). More...

Files

file  src/oal/memory/sapi_memory.c
 Memory pool service: validates parameters, then dispatches to the backend registered via sapi_mem_pool_register_backend() (ADR-005).

Data Structures

struct  sapi_mem_pool_config_t
 Configuration for sapi_mem_pool_create(). More...

Typedefs

typedef struct sapi_mem_pool_impl_s * sapi_mem_pool_handle_t
 Opaque handle to a reserved pool, returned by sapi_mem_pool_create().

Functions

 SAFEAPI_DECLARE_STORAGE (sapi_mem_pool_storage_t, 64U)
 Caller-owned, fixed-size storage backing one sapi_mem_pool_handle_t.
sapi_status_t sapi_mem_pool_create (sapi_mem_pool_storage_t *storage, const sapi_mem_pool_config_t *config, sapi_mem_pool_handle_t *out_handle)
 Reserves a fixed-size-block memory pool.
sapi_status_t sapi_mem_pool_acquire (sapi_mem_pool_handle_t handle, void **out_block)
 Acquires one fixed-size block from the pool.
sapi_status_t sapi_mem_pool_release (sapi_mem_pool_handle_t handle, void *block)
 Returns a previously acquired block to its pool.
sapi_status_t sapi_mem_pool_stats (sapi_mem_pool_handle_t handle, size_t *out_free_blocks, size_t *out_used_blocks)
 Reports current free/used block counts for diagnostics.

Detailed Description

Fixed-size memory pools reserved at initialization (ADR-001).

Typedef Documentation

◆ sapi_mem_pool_handle_t

typedef struct sapi_mem_pool_impl_s* sapi_mem_pool_handle_t

Opaque handle to a reserved pool, returned by sapi_mem_pool_create().

Definition at line 32 of file sapi_memory.h.

Function Documentation

◆ sapi_mem_pool_create()

sapi_status_t sapi_mem_pool_create ( sapi_mem_pool_storage_t * storage,
const sapi_mem_pool_config_t * config,
sapi_mem_pool_handle_t * out_handle )

Reserves a fixed-size-block memory pool.

Parameters
storageCaller-owned storage for the handle's state. Must not be NULL.
configPool configuration. Must not be NULL; config->block_size and config->block_count must both be > 0.
out_handleReceives the created pool's handle. Must not be NULL.
Returns
SAPI_STATUS_OK; SAPI_STATUS_INVALID_PARAM for a bad argument; SAPI_STATUS_NOT_INITIALIZED if no backend is registered (sapi_mem_pool_register_backend()); SAPI_STATUS_NOT_SUPPORTED if the registered backend does not implement create. REQ-OAL-MEM-010

Definition at line 44 of file sapi_memory.c.

◆ sapi_mem_pool_acquire()

sapi_status_t sapi_mem_pool_acquire ( sapi_mem_pool_handle_t handle,
void ** out_block )

Acquires one fixed-size block from the pool.

Parameters
handlePool handle. Must not be NULL.
out_blockReceives a pointer to the acquired block. Must not be NULL; set to NULL on failure.
Returns
SAPI_STATUS_OK; SAPI_STATUS_INVALID_PARAM; SAPI_STATUS_RESOURCE_EXHAUSTED if no blocks remain; SAPI_STATUS_NOT_INITIALIZED/SAPI_STATUS_NOT_SUPPORTED as in sapi_mem_pool_create(). REQ-OAL-MEM-011

Definition at line 77 of file sapi_memory.c.

◆ sapi_mem_pool_release()

sapi_status_t sapi_mem_pool_release ( sapi_mem_pool_handle_t handle,
void * block )

Returns a previously acquired block to its pool.

Parameters
handlePool handle. Must not be NULL.
blockBlock previously returned by sapi_mem_pool_acquire(). Must not be NULL.
Returns
SAPI_STATUS_OK; SAPI_STATUS_INVALID_PARAM; SAPI_STATUS_NOT_INITIALIZED/ SAPI_STATUS_NOT_SUPPORTED as in sapi_mem_pool_create(). REQ-OAL-MEM-012

Definition at line 95 of file sapi_memory.c.

◆ sapi_mem_pool_stats()

sapi_status_t sapi_mem_pool_stats ( sapi_mem_pool_handle_t handle,
size_t * out_free_blocks,
size_t * out_used_blocks )

Reports current free/used block counts for diagnostics.

Parameters
handlePool handle. Must not be NULL.
out_free_blocksReceives the number of free blocks. Must not be NULL.
out_used_blocksReceives the number of used blocks. Must not be NULL.
Returns
SAPI_STATUS_OK; SAPI_STATUS_INVALID_PARAM; SAPI_STATUS_NOT_INITIALIZED/ SAPI_STATUS_NOT_SUPPORTED as in sapi_mem_pool_create(). REQ-OAL-MEM-013

Definition at line 112 of file sapi_memory.c.