Embedded Implementation of Mutexes and Semaphores

Mutexes and Semaphores Demystified
Programming Embedded Systems in C and C++

ChibiOS/RT

Counting Semaphores, Binary Semaphores and Mutexes explained
Mutual Exclusion guide

System Locks

This is the lowest level mechanism, the system is locked by invoking the chSysLock() API and then unlocked by invoking chSysUnlock(). The implementation is architecture dependent but it is guaranteed to, at least, disable the interrupt sources with hardware priority below or equal the kernel level.

Mutexes

The mutexes are the mechanism intended as the most general solution for Mutual Exclusion.

/**
* @brief Locks the specified mutex.
* @post The mutex is locked and inserted in the per-thread stack of owned
* mutexes.
*
* @param[in] mp pointer to the @p Mutex structure
*
* @api
*/
void chMtxLock(Mutex *mp) {

  chSysLock();

  chMtxLockS(mp);

  chSysUnlock();
}

Leave a Reply

Your email address will not be published. Required fields are marked *