Mbed OS Reference
|
The Mutex class is used to synchronize the execution of threads. More...
#include <Mutex.h>
Public Member Functions | |
Mutex () | |
Create and Initialize a Mutex object. More... | |
Mutex (const char *name) | |
Create and Initialize a Mutex object. More... | |
void | lock () |
Wait until a Mutex becomes available. More... | |
bool | trylock () |
Try to lock the mutex, and return immediately. More... | |
bool | trylock_for (uint32_t millisec) |
Try to lock the mutex for a specified time. More... | |
bool | trylock_for (Kernel::Clock::duration_u32 rel_time) |
Try to lock the mutex for a specified time. More... | |
bool | trylock_until (uint64_t millisec) |
Try to lock the mutex until specified time. More... | |
bool | trylock_until (Kernel::Clock::time_point abs_time) |
Try to lock the mutex until specified time. More... | |
void | unlock () |
Unlock the mutex that has previously been locked by the same thread. More... | |
osThreadId_t | get_owner () |
Get the owner the this mutex. More... | |
~Mutex () | |
Mutex destructor. More... | |
The Mutex class is used to synchronize the execution of threads.
This is, for example, used to protect access to a shared resource.
In bare-metal builds, the Mutex class is a dummy, so lock() and unlock() are no-ops.
Mutex | ( | const char * | name | ) |
Create and Initialize a Mutex object.
name | name to be used for this mutex. It has to stay allocated for the lifetime of the thread. |
void lock | ( | ) |
Wait until a Mutex becomes available.
bool trylock | ( | ) |
Try to lock the mutex, and return immediately.
bool trylock_for | ( | uint32_t | millisec | ) |
Try to lock the mutex for a specified time.
millisec | timeout value. |
5s
rather than 5000
. bool trylock_for | ( | Kernel::Clock::duration_u32 | rel_time | ) |
Try to lock the mutex for a specified time.
rel_time | timeout value. |
bool trylock_until | ( | uint64_t | millisec | ) |
Try to lock the mutex until specified time.
millisec | absolute timeout time, referenced to Kernel::get_ms_count() |
Kernel::Clock::now() + 5s
rather than Kernel::get_ms_count() + 5000
. bool trylock_until | ( | Kernel::Clock::time_point | abs_time | ) |
Try to lock the mutex until specified time.
abs_time | absolute timeout time, referenced to Kernel::Clock |
void unlock | ( | ) |
Unlock the mutex that has previously been locked by the same thread.
osThreadId_t get_owner | ( | ) |
Get the owner the this mutex.