QP/C++  8.0.0
Real-Time Embedded Framework
Loading...
Searching...
No Matches
QXMutex Class Reference

Blocking Mutex of the QXK preemptive kernel. More...

Detailed Description

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.

Note
QP::QXMutex should be used in situations when at least one of the extended threads contending for the mutex blocks while holding the mutex (between the QXMutex_lock() and QXMutex_unlock() operations). If no blocking is needed while holding the mutex, the more efficient non-blocking mechanism of selective QXK scheduler locking should be used instead. Selective scheduler locking is available for both basic threads and extended threads, so it is applicable to situations where resources are shared among all these threads.
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 TH_mutex; // <===
. . .
void XThread2::run(QP::QXThread * const thr) {
TH_mutex.init(APP::N_PHILO + 6U); // priority-ceiling mutex
for (;;) {
. . .
TH_mutex.lock(QP::QXTHREAD_NO_TIMEOUT); // lock the mutex
QP::QXThread::delay(5U); // wait more (BLOCK)
TH_mutex.unlock();
}
}
Blocking Mutex of the QXK preemptive kernel.
eXtended (blocking) thread of the QXK preemptive kernel

The documentation for this class was generated from the following file: