Safe API Framework
0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Toggle main menu visibility
Loading...
Searching...
No Matches
rte_memory.c
Go to the documentation of this file.
1
7
#include "
rte/oal/memory/rte_memory.h
"
8
#include "
rte/utils/lifecycle/rte_lifecycle.h
"
9
#include "
rte_osadapter/memory/rte_osadapter_memory.h
"
10
12
14
17
static
const
rte_osadapter_memory_t
*
s_osadapter
= NULL;
18
20
22
23
25
rte_status_t
rte_osadapter_memory_register
(
const
rte_osadapter_memory_t
*osadapter)
26
{
27
rte_status_t
lifecycle_status;
28
29
if
(osadapter == NULL)
30
{
31
return
RTE_STATUS_INVALID_PARAM
;
32
}
33
/* REQ-LIFECYCLE-001 (ADR-026): registering an OSAdapter is a setup-only
34
* action - refuse once the application's setup phase has been locked. */
35
lifecycle_status =
rte_lifecycle_check_setup_allowed
();
36
if
(lifecycle_status !=
RTE_STATUS_OK
)
37
{
38
return
lifecycle_status;
39
}
40
s_osadapter
= osadapter;
41
return
RTE_STATUS_OK
;
42
}
43
44
rte_status_t
rte_mem_pool_create
(rte_mem_pool_storage_t *storage,
45
const
rte_mem_pool_config_t
*config,
46
rte_mem_pool_handle_t
*out_handle)
47
{
48
rte_status_t
lifecycle_status;
49
50
if
((storage == NULL) || (config == NULL) || (out_handle == NULL))
51
{
52
return
RTE_STATUS_INVALID_PARAM
;
53
}
54
if
((config->
block_size
== 0U) || (config->
block_count
== 0U))
55
{
56
return
RTE_STATUS_INVALID_PARAM
;
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 =
rte_lifecycle_check_setup_allowed
();
62
if
(lifecycle_status !=
RTE_STATUS_OK
)
63
{
64
return
lifecycle_status;
65
}
66
if
(
s_osadapter
== NULL)
67
{
68
return
RTE_STATUS_NOT_INITIALIZED
;
69
}
70
if
(
s_osadapter
->create == NULL)
71
{
72
return
RTE_STATUS_NOT_SUPPORTED
;
73
}
74
return
s_osadapter
->create(storage, config, out_handle);
75
}
76
77
rte_status_t
rte_mem_pool_acquire
(
rte_mem_pool_handle_t
handle,
void
**out_block)
78
{
79
if
((handle == NULL) || (out_block == NULL))
80
{
81
return
RTE_STATUS_INVALID_PARAM
;
82
}
83
*out_block = NULL;
84
if
(
s_osadapter
== NULL)
85
{
86
return
RTE_STATUS_NOT_INITIALIZED
;
87
}
88
if
(
s_osadapter
->acquire == NULL)
89
{
90
return
RTE_STATUS_NOT_SUPPORTED
;
91
}
92
return
s_osadapter
->acquire(handle, out_block);
93
}
94
95
rte_status_t
rte_mem_pool_release
(
rte_mem_pool_handle_t
handle,
void
*block)
96
{
97
if
((handle == NULL) || (block == NULL))
98
{
99
return
RTE_STATUS_INVALID_PARAM
;
100
}
101
if
(
s_osadapter
== NULL)
102
{
103
return
RTE_STATUS_NOT_INITIALIZED
;
104
}
105
if
(
s_osadapter
->release == NULL)
106
{
107
return
RTE_STATUS_NOT_SUPPORTED
;
108
}
109
return
s_osadapter
->release(handle, block);
110
}
111
112
rte_status_t
rte_mem_pool_stats
(
rte_mem_pool_handle_t
handle,
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
{
118
return
RTE_STATUS_INVALID_PARAM
;
119
}
120
*out_free_blocks = 0U;
121
*out_used_blocks = 0U;
122
if
(
s_osadapter
== NULL)
123
{
124
return
RTE_STATUS_NOT_INITIALIZED
;
125
}
126
if
(
s_osadapter
->stats == NULL)
127
{
128
return
RTE_STATUS_NOT_SUPPORTED
;
129
}
130
return
s_osadapter
->stats(handle, out_free_blocks, out_used_blocks);
131
}
rte_lifecycle_check_setup_allowed
rte_status_t rte_lifecycle_check_setup_allowed(void)
Convenience check for a setup-only constructor: call this as one of the first checks in any function ...
Definition
rte_lifecycle.c:41
rte_mem_pool_release
rte_status_t rte_mem_pool_release(rte_mem_pool_handle_t handle, void *block)
Returns a previously acquired block to its pool.
Definition
rte_memory.c:95
rte_mem_pool_acquire
rte_status_t rte_mem_pool_acquire(rte_mem_pool_handle_t handle, void **out_block)
Acquires one fixed-size block from the pool.
Definition
rte_memory.c:77
rte_mem_pool_handle_t
struct rte_mem_pool_impl_s * rte_mem_pool_handle_t
Opaque handle to a reserved pool, returned by rte_mem_pool_create().
Definition
rte_memory.h:32
rte_mem_pool_stats
rte_status_t rte_mem_pool_stats(rte_mem_pool_handle_t handle, size_t *out_free_blocks, size_t *out_used_blocks)
Reports current free/used block counts for diagnostics.
Definition
rte_memory.c:112
rte_mem_pool_create
rte_status_t rte_mem_pool_create(rte_mem_pool_storage_t *storage, const rte_mem_pool_config_t *config, rte_mem_pool_handle_t *out_handle)
Reserves a fixed-size-block memory pool.
Definition
rte_memory.c:44
rte_status_t
rte_status_t
Common result/status codes.
Definition
rte_status.h:27
RTE_STATUS_OK
@ RTE_STATUS_OK
Definition
rte_status.h:28
RTE_STATUS_INVALID_PARAM
@ RTE_STATUS_INVALID_PARAM
Definition
rte_status.h:29
RTE_STATUS_NOT_SUPPORTED
@ RTE_STATUS_NOT_SUPPORTED
Definition
rte_status.h:34
RTE_STATUS_NOT_INITIALIZED
@ RTE_STATUS_NOT_INITIALIZED
Definition
rte_status.h:30
s_osadapter
static const rte_osadapter_clocksync_t * s_osadapter
Definition
rte_clocksync.c:18
rte_lifecycle.h
Process-wide application setup-phase lock (ADR-026).
rte_memory.h
OS Abstraction Layer - Static memory reservation service.
rte_osadapter_memory.h
OSAdapter interface for static memory pool management.
rte_osadapter_memory_register
rte_status_t rte_osadapter_memory_register(const rte_osadapter_memory_t *adapter)
Registers the OSAdapter memory implementation.
Definition
rte_memory.c:25
rte_mem_pool_config_t
Configuration for rte_mem_pool_create().
Definition
rte_memory.h:36
rte_mem_pool_config_t::block_count
size_t block_count
Definition
rte_memory.h:38
rte_mem_pool_config_t::block_size
size_t block_size
Definition
rte_memory.h:37
rte_osadapter_memory_t
OSAdapter memory pool operations vtable.
Definition
rte_osadapter_memory.h:26
src
oal
memory
rte_memory.c
Generated by
1.18.0