Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
sapi_mutex.c
Go to the documentation of this file.
1
10
12
14
17static const sapi_mutex_backend_t *s_backend = NULL;
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_mutex_create(sapi_mutex_storage_t *storage, sapi_mutex_handle_t *out_handle)
45{
46 if ((storage == NULL) || (out_handle == NULL))
47 {
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 (sapi_appmanager_run(),
53 * after ops->init() succeeds) - same posture as sapi_timer_create()/
54 * sapi_task_create(). */
55 {
57
58 if (lifecycle_status != SAPI_STATUS_OK)
59 {
60 return lifecycle_status;
61 }
62 }
63 if (s_backend == NULL)
64 {
66 }
67 if (s_backend->create == NULL)
68 {
70 }
71 return s_backend->create(storage, out_handle);
72}
73
75{
76 if (handle == NULL)
77 {
79 }
80 if (s_backend == NULL)
81 {
83 }
84 if (s_backend->lock == NULL)
85 {
87 }
88 return s_backend->lock(handle);
89}
90
92{
93 if (handle == NULL)
94 {
96 }
97 if (s_backend == NULL)
98 {
100 }
101 if (s_backend->unlock == NULL)
102 {
104 }
105 return s_backend->unlock(handle);
106}
107
109{
110 if (handle == NULL)
111 {
113 }
114 if (s_backend == NULL)
115 {
117 }
118 if (s_backend->destroy == NULL)
119 {
121 }
122 return s_backend->destroy(handle);
123}
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_mutex_register_backend(const sapi_mutex_backend_t *backend)
Registers the backend implementation used by every sapi_mutex_* call. This is how an integrator suppl...
Definition sapi_mutex.c:25
struct sapi_mutex_impl_s * sapi_mutex_handle_t
Definition sapi_mutex.h:44
sapi_status_t sapi_mutex_destroy(sapi_mutex_handle_t handle)
Destroys a mutex, releasing any backend resources bound to it. Must not be called while any task hold...
Definition sapi_mutex.c:108
sapi_status_t sapi_mutex_unlock(sapi_mutex_handle_t handle)
Releases a mutex previously locked by the calling task.
Definition sapi_mutex.c:91
sapi_status_t sapi_mutex_create(sapi_mutex_storage_t *storage, sapi_mutex_handle_t *out_handle)
Creates (and initializes, unlocked) a mutex bound to caller-owned storage.
Definition sapi_mutex.c:44
sapi_status_t sapi_mutex_lock(sapi_mutex_handle_t handle)
Blocks the calling task until it holds the mutex.
Definition sapi_mutex.c:74
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 - Mutual exclusion service.
OS-backend adaptation surface for the Mutex service (ADR-033, ADR-021).
Backend vtable: an integrator's implementation of the mutex service for a specific OS/RTOS/BSP target...
sapi_status_t(*) unlock(sapi_mutex_handle_t handle)
Backend implementation of sapi_mutex_unlock(). May be NULL.
sapi_status_t(*) destroy(sapi_mutex_handle_t handle)
Backend implementation of sapi_mutex_destroy(). May be NULL.
sapi_status_t(*) create(sapi_mutex_storage_t *storage, sapi_mutex_handle_t *out_handle)
Backend implementation of sapi_mutex_create(). May be NULL.
sapi_status_t(*) lock(sapi_mutex_handle_t handle)
Backend implementation of sapi_mutex_lock(). May be NULL.