Blocking Mutex of the QXK preemptive kernel. More...
#include "qxk.hpp"
Public Member Functions | |
QXMutex () | |
void | init (QPrioSpec const prioSpec) noexcept |
bool | lock (QTimeEvtCtr const nTicks=QXTHREAD_NO_TIMEOUT) noexcept |
bool | tryLock () noexcept |
void | unlock () noexcept |
Private Attributes | |
QActive | m_ao |
QPSet | m_waitSet |
Blocking Mutex of the QXK preemptive kernel.
QP::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, QP::QXMutex requires its own unique QP priority level, which cannot be used by any thread or any other QP::QXMutex.
If initialized with preemption-ceiling of zero, QP::QXMutex does not use the priority-ceiling protocol and does not require a unique QP priority (see QXMutex::init()).
QP::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.
QP::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).
QP::QXMutex::QXMutex | ( | ) |
Definition at line 76 of file qxk_mutex.cpp.
|
noexcept |
Initialize the QXK priority-ceiling mutex QP::QXMutex
Initialize the QXK priority ceiling mutex.
[in] | prioSpec | the priority specification for the mutex (See also QP::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 QP::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).
Definition at line 81 of file qxk_mutex.cpp.
|
noexcept |
Lock the QXK priority-ceiling mutex QXMutex
[in] | nTicks | number of clock ticks (at the associated rate) to wait for the mutex. The value of QP::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 99 of file qxk_mutex.cpp.
|
noexcept |
Try to lock the QXK priority-ceiling mutex QP::QXMutex
qxk_mutex:300
qxk_mutex:301
qxk_mutex:302
Definition at line 246 of file qxk_mutex.cpp.
|
noexcept |
Unlock the QXK priority-ceiling mutex QP::QXMutex
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 350 of file qxk_mutex.cpp.
|
private |
|
private |