3#define _POSIX_C_SOURCE 200809L
34#include "rte/oal/memory/rte_mem_util.h"
41 pthread_mutex_t mutex;
42 rte_mutex_handle_t self_handle;
48typedef char posix_mutex_storage_fits_[(
sizeof(
posix_mutex_state_t) <=
sizeof(rte_mutex_storage_t)) ? 1 : -1];
51static rte_status_t
osadapter_create(rte_mutex_storage_t *storage, rte_mutex_handle_t *out_handle);
52static rte_status_t osadapter_lock(rte_mutex_handle_t handle);
53static rte_status_t osadapter_unlock(rte_mutex_handle_t handle);
54static rte_status_t osadapter_destroy(rte_mutex_handle_t handle);
55static rte_status_t osadapter_lock_timed(rte_mutex_handle_t handle, rte_duration_ms_t timeout_ms);
59 osadapter_destroy, osadapter_lock_timed };
73static rte_status_t
osadapter_create(rte_mutex_storage_t *storage, rte_mutex_handle_t *out_handle)
75 rte_status_t status = RTE_STATUS_OK;
77 pthread_mutexattr_t attr;
79 if ((storage == NULL) || (out_handle == NULL))
81 status = RTE_STATUS_INVALID_PARAM;
86 rte_mem_set(state, 0,
sizeof(*state));
92 if (pthread_mutexattr_init(&attr) != 0)
94 status = RTE_STATUS_INTERNAL_ERROR;
98 if (pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT) != 0)
100 status = RTE_STATUS_INTERNAL_ERROR;
102 else if (pthread_mutex_init(&state->mutex, &attr) != 0)
104 status = RTE_STATUS_INTERNAL_ERROR;
110 (void)pthread_mutexattr_destroy(&attr);
113 if (status == RTE_STATUS_OK)
115 state->self_handle = (rte_mutex_handle_t)(
void *)storage;
116 *out_handle = state->self_handle;
121 POSIX_OSA_REPORT_RT_ATTRIBUTE(
"mutex refused priority inheritance - create failed");
128static rte_status_t osadapter_lock(rte_mutex_handle_t handle)
134 return RTE_STATUS_INVALID_PARAM;
136 if (pthread_mutex_lock(&state->mutex) != 0)
138 return RTE_STATUS_INTERNAL_ERROR;
140 return RTE_STATUS_OK;
143static rte_status_t osadapter_unlock(rte_mutex_handle_t handle)
149 return RTE_STATUS_INVALID_PARAM;
151 if (pthread_mutex_unlock(&state->mutex) != 0)
153 return RTE_STATUS_INTERNAL_ERROR;
155 return RTE_STATUS_OK;
158static rte_status_t osadapter_destroy(rte_mutex_handle_t handle)
164 return RTE_STATUS_INVALID_PARAM;
166 if (pthread_mutex_destroy(&state->mutex) != 0)
168 return RTE_STATUS_INTERNAL_ERROR;
170 return RTE_STATUS_OK;
173static rte_status_t osadapter_lock_timed(rte_mutex_handle_t handle, rte_duration_ms_t timeout_ms)
180 status = RTE_STATUS_INVALID_PARAM;
Real POSIX/Linux OSAdapter for every OAL service (ADR-018).
const rte_osadapter_mutex_t * rte_posix_osadapter_mutex(void)
The POSIX rte_mutex OSAdapter (a thin pthread_mutex_t wrapper, ADR-033).
static rte_status_t osadapter_create(rte_ipc_storage_t *storage, const rte_ipc_config_t *config, rte_ipc_handle_t *out_handle)
rte_status_t posix_osa_lock_bounded(pthread_mutex_t *mutex, rte_duration_ms_t timeout_ms)
Waits at most timeout_ms for a pthread mutex.
Private helper: a bounded wait for a pthread mutex (OSA rule R2: every wait bounded).
static const rte_osadapter_mutex_t s_posix_mutex_osadapter
Private helper: reports a real-time attribute this OSAdapter could not apply (OSA rules R1/R2/R6).