NAME | SYNOPSIS | FEATURES | DESCRIPTION | RETURN VALUE | ERRORS | ATTRIBUTES | SEE ALSO
#include <sync/chRtMutex.h>int rtMutexInit(KnRtMutex * mutex);
RTMUTEX
Realtime mutexes are binary semaphores used to protect shared data from concurrent access: a realtime mutex is a two state variable - free or locked. When a thread is blocking higher priority threads because it owns one or more realtime mutexes, it executes either its highest prioirty, or the priority of the highest priority thread waiting on any of the realtime mutexes owned by the thread.
Realtime mutexes are KnRtMutex structures allocated in user memory.
The rtMutexInit function initializes the realtime mutex whose address is mutex. The mutex is initialized as free.
The rtMutexGet function is used to acquire a realtime mutex. If the mutex is free, it becomes locked and the caller continues to execute normally. If the mutex is locked, the caller is blocked. The owner thread inherits the priority level of the calling thread as long as it continues to own the mutex. The implementation updates its execution prioirty to the maximum of its assigned priority plus all its inherited priority. Futhermore, if the owner thread itself becomes blocked on another realtime mutex, the same prioirty inheritance effect is propagated recursively to this other owner thread.
The rtMutexRel function is used to release a realtime mutex. If threads are blocked behind the mutex, the thread with the highest priority is awakened. The priority of the calling thread can be reduced by using rtMutexRel .
The rtMutexTry function is an attempt to acquire a realtime mutex: it has the same effect as rtMutexGet, except that if the mutex is locked, the thread is not blocked (a return code is provided).
Any priority adjustments caused by priority inheritance are transparent and are not visible through the threadScheduler interface. In other words, the priority value returned from threadScheduler will be the value specified by the most recent threadScheduler or threadCreate call.
A blocking rtMutexGet is NONABORTABLE (see threadAbort (2K)).
The rtMutexTry function returns 0 if the mutex was already locked, 1 if it was free. Upon successful completion of rtMutexInit, rtMutexGet and rtMutexRel, 0 is returned. Otherwise, a negative error code is returned.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
---|---|
Interface Stability | Evolving |
NAME | SYNOPSIS | FEATURES | DESCRIPTION | RETURN VALUE | ERRORS | ATTRIBUTES | SEE ALSO