Blocking Mutex of the QXK preemptive kernel. More...
#include "qxk.h"
Public Member Functions | |
void | QXMutex_init (QXMutex *const me, QPrioSpec const prioSpec) |
bool | QXMutex_lock (QXMutex *const me, QTimeEvtCtr const nTicks) |
bool | QXMutex_tryLock (QXMutex *const me) |
void | QXMutex_unlock (QXMutex *const me) |
Private Attributes | |
QActive | ao |
QPSet | waitSet |
Blocking Mutex of the QXK preemptive kernel.
QXMutex is a blocking mutual exclusion mechanism that can also apply the priority-ceiling protocol to avoid unbounded priority inversion (if initialized with a non-zero ceiling priority, see QXMutex_init()). In that case, QXMutex requires its own unique QP priority level, which cannot be used by any thread or any other QXMutex.
If initialized with preemption-ceiling of zero, QXMutex does not use the priority-ceiling protocol and does not require a unique QP priority (see QXMutex_init()).
QXMutex is recursive (re-entrant), which means that it can be locked multiple times (up to 255 levels) by the same thread without causing deadlock.
QXMutex is primarily intended for the extended (blocking) threads, but can also be used by the basic threads through the non-blocking QXMutex_tryLock() API.
The following example illustrates how to instantiate and use the mutex to protect a shared resource (random seed of a pseudo-random number generator).
Initialize the QXK priority-ceiling mutex QXMutex
Initialize the QXK priority ceiling mutex.
[in,out] | me | current instance pointer (see oop) |
[in] | prioSpec | the priority specification for the mutex (See also QPrioSpec). This value might also be zero. |
qxk_mutex:100
prioSpec == 0
means that the priority-ceiling protocol shall not be used by this mutex. Such mutex will not change (boost) the priority of the holding threads.Conversely, prioSpec != 0
means that the priority-ceiling protocol shall be used by this mutex. Such mutex will temporarily boost the priority and priority-threshold of the holding thread to the priority specification in prioSpec
(see QPrioSpec).
The following example illustrates how to instantiate and use the mutex to protect a shared resource (random seed of a pseudo-random number generator).
bool QXMutex_lock | ( | QXMutex *const | me, |
QTimeEvtCtr const | nTicks ) |
Lock the QXK priority-ceiling mutex QXMutex
[in,out] | me | current instance pointer (see oop) |
[in] | nTicks | number of clock ticks (at the associated rate) to wait for the mutex. The value of QXTHREAD_NO_TIMEOUT indicates that no timeout will occur and the mutex could block indefinitely. |
qxk_mutex:200
qxk_mutex:201
qxk_mutex:202
The following example illustrates how to instantiate and use the mutex to protect a shared resource (random seed of a pseudo-random number generator).
Definition at line 94 of file qxk_mutex.c.
bool QXMutex_tryLock | ( | QXMutex *const | me | ) |
Try to lock the QXK priority-ceiling mutex QXMutex
[in,out] | me | current instance pointer (see oop) |
qxk_mutex:300
qxk_mutex:301
qxk_mutex:302
Definition at line 243 of file qxk_mutex.c.
void QXMutex_unlock | ( | QXMutex *const | me | ) |
Unlock the QXK priority-ceiling mutex QXMutex
[in,out] | me | current instance pointer (see oop) |
qxk_mutex:400
qxk_mutex:401
qxk_mutex:402
The following example illustrates how to instantiate and use the mutex to protect a shared resource (random seed of a pseudo-random number generator).
Definition at line 347 of file qxk_mutex.c.
|
private |
|
private |