RTE OSAdapter POSIX 0.1.0 build 41b3eb3
POSIX/Linux OAL OSAdapter for Platform_RTE
Loading...
Searching...
No Matches
rte_posix_osadapter_lock.h File Reference

Private helper: a bounded wait for a pthread mutex (OSA rule R2: every wait bounded). More...

#include <pthread.h>
#include "rte/utils/status/rte_status.h"
#include "rte/utils/types/rte_types.h"
Include dependency graph for rte_posix_osadapter_lock.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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.

Detailed Description

Private helper: a bounded wait for a pthread mutex (OSA rule R2: every wait bounded).

One implementation of the timed-lock semantics (REQ-OAL-MUTEX-014) shared by the mutex OSAdapter's lock_timed and the memory OSAdapter's pool lock (REQ-OAL-MEM-015). Not installed: an internal header of this product, like rte_posix_osadapter_poll.h. A source file including it defines _POSIX_C_SOURCE before its first include (glibc declares the pthread timed-lock and clock calls only under a POSIX feature-test macro).

Definition in file rte_posix_osadapter_lock.h.

Function Documentation

◆ posix_osa_lock_bounded()

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.

timeout_ms == 0 is one pthread_mutex_trylock(). Otherwise:

  • Linux: pthread_mutex_timedlock() against an absolute CLOCK_REALTIME deadline - a blocking wait that keeps the priority-inheritance boost. Known limit: the deadline is on the wall clock, so a clock step while a task waits shortens or lengthens that one wait. pthread_mutex_clocklock(CLOCK_MONOTONIC) is not used: glibc accepts it on a PI mutex only when kernel and libc support FUTEX_LOCK_PI2.
  • Other hosts (macOS has no pthread_mutex_timedlock): a pthread_mutex_trylock() loop against a CLOCK_MONOTONIC deadline with a sleep of at most 1 ms between tries, never past the deadline. No priority-inheritance boost while polling (the holder is not boosted by a task that is not blocked on the mutex) - development host only.

A failed clock read returns RTE_STATUS_INTERNAL_ERROR, never an unbounded wait.

Parameters
mutexInitialised pthread mutex to lock. Must not be NULL.
timeout_msMaximum time to wait, in milliseconds; 0 is one non-blocking try.
Returns
RTE_STATUS_OK with the mutex held; RTE_STATUS_TIMEOUT when it was not acquired within timeout_ms (the mutex is then not held); RTE_STATUS_INVALID_PARAM for a NULL mutex; RTE_STATUS_INTERNAL_ERROR for any other platform failure (a failed clock read, an error from the pthread call). REQ-OAL-MUTEX-014, REQ-OAL-MEM-015

Local variables declarations Global variables declarations Global functions

Definition at line 44 of file rte_posix_osadapter_lock.c.