Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
sapi_memory.c
Go to the documentation of this file.
1
10
12
14
18
20
22
23
26{
27 sapi_status_t lifecycle_status;
28
29 if (backend == NULL)
30 {
32 }
33 /* REQ-LIFECYCLE-001 (ADR-026): registering a backend is a setup-only
34 * action - refuse once the application's setup phase has been locked. */
35 lifecycle_status = sapi_lifecycle_check_setup_allowed();
36 if (lifecycle_status != SAPI_STATUS_OK)
37 {
38 return lifecycle_status;
39 }
40 s_backend = backend;
41 return SAPI_STATUS_OK;
42}
43
44sapi_status_t sapi_mem_pool_create(sapi_mem_pool_storage_t *storage,
45 const sapi_mem_pool_config_t *config,
46 sapi_mem_pool_handle_t *out_handle)
47{
48 sapi_status_t lifecycle_status;
49
50 if ((storage == NULL) || (config == NULL) || (out_handle == NULL))
51 {
53 }
54 if ((config->block_size == 0U) || (config->block_count == 0U))
55 {
57 }
58 *out_handle = NULL;
59 /* REQ-LIFECYCLE-001 (ADR-026): a memory pool is a setup-only resource -
60 * refuse once the application's setup phase has been locked. */
61 lifecycle_status = sapi_lifecycle_check_setup_allowed();
62 if (lifecycle_status != SAPI_STATUS_OK)
63 {
64 return lifecycle_status;
65 }
66 if (s_backend == NULL)
67 {
69 }
70 if (s_backend->create == NULL)
71 {
73 }
74 return s_backend->create(storage, config, out_handle);
75}
76
78{
79 if ((handle == NULL) || (out_block == NULL))
80 {
82 }
83 *out_block = NULL;
84 if (s_backend == NULL)
85 {
87 }
88 if (s_backend->acquire == NULL)
89 {
91 }
92 return s_backend->acquire(handle, out_block);
93}
94
96{
97 if ((handle == NULL) || (block == NULL))
98 {
100 }
101 if (s_backend == NULL)
102 {
104 }
105 if (s_backend->release == NULL)
106 {
108 }
109 return s_backend->release(handle, block);
110}
111
113 size_t *out_free_blocks,
114 size_t *out_used_blocks)
115{
116 if ((handle == NULL) || (out_free_blocks == NULL) || (out_used_blocks == NULL))
117 {
119 }
120 *out_free_blocks = 0U;
121 *out_used_blocks = 0U;
122 if (s_backend == NULL)
123 {
125 }
126 if (s_backend->stats == NULL)
127 {
129 }
130 return s_backend->stats(handle, out_free_blocks, out_used_blocks);
131}
sapi_status_t sapi_lifecycle_check_setup_allowed(void)
Convenience check for a setup-only constructor: call this as one of the first checks in any function ...
sapi_status_t sapi_mem_pool_register_backend(const sapi_mem_pool_backend_t *backend)
Registers the backend implementation used by every sapi_mem_pool_* call (ADR-005 section 2....
Definition sapi_memory.c:25
sapi_status_t sapi_mem_pool_acquire(sapi_mem_pool_handle_t handle, void **out_block)
Acquires one fixed-size block from the pool.
Definition sapi_memory.c:77
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.
Definition sapi_memory.c:44
struct sapi_mem_pool_impl_s * sapi_mem_pool_handle_t
Opaque handle to a reserved pool, returned by sapi_mem_pool_create().
Definition sapi_memory.h:32
sapi_status_t sapi_mem_pool_release(sapi_mem_pool_handle_t handle, void *block)
Returns a previously acquired block to its pool.
Definition sapi_memory.c:95
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.
sapi_status_t
Common result/status codes.
Definition sapi_status.h:27
@ SAPI_STATUS_NOT_SUPPORTED
Definition sapi_status.h:34
@ SAPI_STATUS_INVALID_PARAM
Definition sapi_status.h:29
@ SAPI_STATUS_NOT_INITIALIZED
Definition sapi_status.h:30
@ SAPI_STATUS_OK
Definition sapi_status.h:28
static const sapi_clocksync_backend_t * s_backend
Process-wide application setup-phase lock (ADR-026).
OS Abstraction Layer - Static memory reservation service.
OS-backend adaptation surface for the static memory pool service (ADR-005, ADR-021).
Backend vtable: an integrator's implementation of the memory pool service (ADR-005)....
sapi_status_t(*) acquire(sapi_mem_pool_handle_t handle, void **out_block)
Backend implementation of sapi_mem_pool_acquire(). May be NULL.
sapi_status_t(*) create(sapi_mem_pool_storage_t *storage, const sapi_mem_pool_config_t *config, sapi_mem_pool_handle_t *out_handle)
Backend implementation of sapi_mem_pool_create(). May be NULL.
sapi_status_t(*) stats(sapi_mem_pool_handle_t handle, size_t *out_free_blocks, size_t *out_used_blocks)
Backend implementation of sapi_mem_pool_stats(). May be NULL.
sapi_status_t(*) release(sapi_mem_pool_handle_t handle, void *block)
Backend implementation of sapi_mem_pool_release(). May be NULL.
Configuration for sapi_mem_pool_create().
Definition sapi_memory.h:36