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_mutex.c
Go to the documentation of this file.
1
7
#include "
rte/utils/lifecycle/rte_lifecycle.h
"
8
#include "
rte/oal/mutex/rte_mutex.h
"
9
#include "
rte_osadapter/mutex/rte_osadapter_mutex.h
"
10
12
14
17
static
const
rte_osadapter_mutex_t
*
s_osadapter
= NULL;
18
20
22
23
25
rte_status_t
rte_osadapter_mutex_register
(
const
rte_osadapter_mutex_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_mutex_create
(rte_mutex_storage_t *storage,
rte_mutex_handle_t
*out_handle)
45
{
46
if
((storage == NULL) || (out_handle == NULL))
47
{
48
return
RTE_STATUS_INVALID_PARAM
;
49
}
50
*out_handle = NULL;
51
/* REQ-LIFECYCLE-001 (ADR-026): a mutex is a setup-only resource - refuse
52
* once the application's setup phase has been locked (rte_appmanager_run(),
53
* after ops->init() succeeds) - same posture as rte_timer_create()/
54
* rte_task_create(). */
55
{
56
rte_status_t
lifecycle_status =
rte_lifecycle_check_setup_allowed
();
57
58
if
(lifecycle_status !=
RTE_STATUS_OK
)
59
{
60
return
lifecycle_status;
61
}
62
}
63
if
(
s_osadapter
== NULL)
64
{
65
return
RTE_STATUS_NOT_INITIALIZED
;
66
}
67
if
(
s_osadapter
->create == NULL)
68
{
69
return
RTE_STATUS_NOT_SUPPORTED
;
70
}
71
return
s_osadapter
->create(storage, out_handle);
72
}
73
74
rte_status_t
rte_mutex_lock
(
rte_mutex_handle_t
handle)
75
{
76
if
(handle == NULL)
77
{
78
return
RTE_STATUS_INVALID_PARAM
;
79
}
80
if
(
s_osadapter
== NULL)
81
{
82
return
RTE_STATUS_NOT_INITIALIZED
;
83
}
84
if
(
s_osadapter
->lock == NULL)
85
{
86
return
RTE_STATUS_NOT_SUPPORTED
;
87
}
88
return
s_osadapter
->lock(handle);
89
}
90
91
rte_status_t
rte_mutex_lock_timed
(
rte_mutex_handle_t
handle,
rte_duration_ms_t
timeout_ms)
92
{
93
/* REQ-OAL-MUTEX-014: same checks as rte_mutex_lock(); not lifecycle-gated
94
* (an operational call). The timeout and the OSAdapter's result are
95
* passed through unchanged. */
96
if
(handle == NULL)
97
{
98
return
RTE_STATUS_INVALID_PARAM
;
99
}
100
if
(
s_osadapter
== NULL)
101
{
102
return
RTE_STATUS_NOT_INITIALIZED
;
103
}
104
if
(
s_osadapter
->lock_timed == NULL)
105
{
106
return
RTE_STATUS_NOT_SUPPORTED
;
107
}
108
return
s_osadapter
->lock_timed(handle, timeout_ms);
109
}
110
111
rte_status_t
rte_mutex_unlock
(
rte_mutex_handle_t
handle)
112
{
113
if
(handle == NULL)
114
{
115
return
RTE_STATUS_INVALID_PARAM
;
116
}
117
if
(
s_osadapter
== NULL)
118
{
119
return
RTE_STATUS_NOT_INITIALIZED
;
120
}
121
if
(
s_osadapter
->unlock == NULL)
122
{
123
return
RTE_STATUS_NOT_SUPPORTED
;
124
}
125
return
s_osadapter
->unlock(handle);
126
}
127
128
rte_status_t
rte_mutex_destroy
(
rte_mutex_handle_t
handle)
129
{
130
if
(handle == NULL)
131
{
132
return
RTE_STATUS_INVALID_PARAM
;
133
}
134
if
(
s_osadapter
== NULL)
135
{
136
return
RTE_STATUS_NOT_INITIALIZED
;
137
}
138
if
(
s_osadapter
->destroy == NULL)
139
{
140
return
RTE_STATUS_NOT_SUPPORTED
;
141
}
142
return
s_osadapter
->destroy(handle);
143
}
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_mutex_destroy
rte_status_t rte_mutex_destroy(rte_mutex_handle_t handle)
Destroys a mutex, releasing any OSAdapter resources bound to it. Must not be called while any task ho...
Definition
rte_mutex.c:128
rte_mutex_lock_timed
rte_status_t rte_mutex_lock_timed(rte_mutex_handle_t handle, rte_duration_ms_t timeout_ms)
Waits at most timeout_ms for the mutex (OSA rule R2: every wait bounded).
Definition
rte_mutex.c:91
rte_mutex_create
rte_status_t rte_mutex_create(rte_mutex_storage_t *storage, rte_mutex_handle_t *out_handle)
Creates (and initializes, unlocked) a priority-inheritance mutex bound to caller-owned storage (REQ-O...
Definition
rte_mutex.c:44
rte_mutex_unlock
rte_status_t rte_mutex_unlock(rte_mutex_handle_t handle)
Releases a mutex previously locked by the calling task.
Definition
rte_mutex.c:111
rte_mutex_handle_t
struct rte_mutex_impl_s * rte_mutex_handle_t
Definition
rte_mutex.h:47
rte_mutex_lock
rte_status_t rte_mutex_lock(rte_mutex_handle_t handle)
Blocks the calling task until it holds the mutex.
Definition
rte_mutex.c:74
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
rte_duration_ms_t
uint32_t rte_duration_ms_t
Definition
rte_types.h:27
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_mutex.h
OS Abstraction Layer - Mutual exclusion service.
rte_osadapter_mutex.h
OSAdapter interface for mutual exclusion.
rte_osadapter_mutex_register
rte_status_t rte_osadapter_mutex_register(const rte_osadapter_mutex_t *adapter)
Registers the OSAdapter mutex implementation.
Definition
rte_mutex.c:25
rte_osadapter_mutex_t
OSAdapter mutex operations vtable.
Definition
rte_osadapter_mutex.h:35
src
oal
mutex
rte_mutex.c
Generated by
1.18.0