This library provides an API and generic implementation of mutexes.
More...
This library provides an API and generic implementation of mutexes.
Calling code should manipulate mutexes through the mutex_try_lock() and mutex_unlock() macros. By default, those macros will expand to the generic mutex manipulation implementations provided here. While these will work, they do reply on disabling the master interrupt in order to perform the lock/unlock operation.
It is possible to override those generic implementation with CPU-specific implementations that exploit synchronisation instructions. To do so, create a CPU-specific header file. In this file, define mutex_try_lock() and mutex_unlock() to expand to the respective CPU function names. These can (but do not have to) be inlined. Then define MUTEX_CONF_ARCH_HEADER_PATH as this header's filename.
◆ mutex_try_lock
Try to lock a mutex.
- Parameters
-
m | A pointer to the mutex to be locked |
- Return values
-
true | Locking succeeded |
false | Locking failed (the mutex is already locked) |
This macro will expand to mutex_generic_try_lock() or to a CPU-provided implementation. Platform-independent code should use this macro instead of mutex_generic_try_lock().
Definition at line 91 of file mutex.h.
◆ mutex_unlock
Unlock a previously acquired mutex.
- Parameters
-
m | A pointer to the mutex to be unlocked |
This macro will expand to mutex_generic_unlock() or to a CPU-provided implementation. Platform-independent code should use this macro instead of mutex_generic_unlock().
Definition at line 103 of file mutex.h.
◆ mutex_t
typedef uint_fast8_t mutex_t |
Mutex data type.
It is possible for the platform to override this with its own typedef. In this scenario, make sure to also define MUTEX_CONF_HAS_MUTEX_T as 1.
Definition at line 77 of file mutex.h.
◆ mutex_generic_try_lock()
bool mutex_generic_try_lock |
( |
volatile mutex_t * |
mutex | ) |
|
Try to lock a mutex.
- Parameters
-
mutex | A pointer to the mutex to be locked |
- Return values
-
true | Locking succeeded |
false | Locking failed (the mutex is already locked) |
Do not call this function directly. Use the mutex_try_lock() macro instead.
Definition at line 45 of file mutex.c.
◆ mutex_generic_unlock()
void mutex_generic_unlock |
( |
volatile mutex_t * |
mutex | ) |
|
Unlock a previously acquired mutex.
- Parameters
-
mutex | A pointer to the mutex to be unlocked |
Do not call this function directly. Use the mutex_unlock() macro instead.
Definition at line 61 of file mutex.c.