Blocking Mutex of the QXK preemptive kernel. More...
#include <qxk.hpp>
Public Member Functions | |
| QXMutex () | |
| void | init (QPrioSpec const prioSpec) noexcept |
| Initialize the QXK priority-ceiling mutex QP::QXMutex. | |
| bool | lock (QTimeEvtCtr const nTicks=QXTHREAD_NO_TIMEOUT) noexcept |
| Lock the QXK priority-ceiling mutex ::QXMutex. | |
| bool | tryLock () noexcept |
| Try to lock the QXK priority-ceiling mutex QP::QXMutex. | |
| void | unlock () noexcept |
| Unlock the QXK priority-ceiling mutex QP::QXMutex. | |
Private Member Functions | |
| bool | tryAcq_ (QXThread *const curr) noexcept |
| void | relOneThr_ () noexcept |
Private Attributes | |
| QActive | m_ao |
| Active object used as a placeholder AO for this mutex in QActive_registry_[]. | |
| QPSet | m_waitSet |
| Set of extended-threads waiting on this mutex. | |
Friends | |
| class | QS |
Blocking Mutex of the QXK preemptive kernel.
Details
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.
Usage
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 52 of file qxk_mutex.cpp.
|
noexcept |
Initialize the QXK priority-ceiling mutex QP::QXMutex.
Details
Initialize the QXK priority ceiling mutex.
| [in] | prioSpec | the priority specification for the mutex (See also QP::QPrioSpec). This value might also be zero. |
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).
Usage
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 57 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. |
Usage
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 158 of file qxk_mutex.cpp.
|
noexcept |
Try to lock the QXK priority-ceiling mutex QP::QXMutex.
Definition at line 228 of file qxk_mutex.cpp.
|
noexcept |
Unlock the QXK priority-ceiling mutex QP::QXMutex.
Usage
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 260 of file qxk_mutex.cpp.
|
privatenoexcept |
Definition at line 75 of file qxk_mutex.cpp.
|
privatenoexcept |
Definition at line 338 of file qxk_mutex.cpp.
|
private |
|
private |