![]() |
CMSIS-RTOS
Version 1.02
CMSIS-RTOS API: Generic RTOS interface for Cortex-M processor-based devices.
|
Synchronize thread execution with a Mutex. More...
Macros | |
#define | osMutexDef(name) const osMutexDef_t os_mutex_def_##name = { 0 } |
Define a Mutex. | |
#define | osMutex(name) &os_mutex_def_##name |
Access a Mutex definition. | |
Functions | |
osMutexId | osMutexCreate (const osMutexDef_t *mutex_def) |
Create and Initialize a Mutex object. | |
osStatus | osMutexWait (osMutexId mutex_id, uint32_t millisec) |
Wait until a Mutex becomes available. | |
osStatus | osMutexRelease (osMutexId mutex_id) |
Release a Mutex that was obtained by osMutexWait. | |
osStatus | osMutexDelete (osMutexId mutex_id) |
Delete a Mutex that was created by osMutexCreate. | |
The Mutex Management function group is used to synchronize the execution of threads. Mutually exclusive (known as Mutex) is commonly used in various operating systems for resource management. Many resources in a microcontroller device can only be used by one thread at a time (for example communication channels). Mutexes are used to protect access to a shared resource. A Mutex is created and then passed between the threads (they can acquire and release the Mutex).
#define osMutex | ( | name | ) | &os_mutex_def_##name |
Access to mutex object for the functions osMutexCreate.
name | name of the mutex object. |
#define osMutexDef | ( | name | ) | const osMutexDef_t os_mutex_def_##name = { 0 } |
Define a mutex object that is referenced by osMutex.
name | name of the mutex object. |
osMutexId osMutexCreate | ( | const osMutexDef_t * | mutex_def | ) |
[in] | mutex_def | mutex definition referenced with osMutex. |
Create and initialize a Mutex object.
Code Example
[in] | mutex_id | mutex ID obtained by osMutexCreate. |
Delete a Mutex object. The function releases internal memory obtained for Mutex handling. After this call the mutex_id is no longer valid and cannot be used. The Mutex may be created again using the function osMutexCreate.
Code Example
[in] | mutex_id | mutex ID obtained by osMutexCreate. |
Release a Mutex that was obtained with osMutexWait. Other threads that currently wait for the same mutex will be now put into the state READY.
Code Example
[in] | mutex_id | mutex ID obtained by osMutexCreate. |
[in] | millisec | timeout value or 0 in case of no time-out. |
Wait until a Mutex becomes available. If no other thread has obtained the Mutex, the function instantly returns and blocks the mutex object.
The argument millisec specifies how long the system waits for a mutex. While the system waits the thread that is calling this function is put into the state WAITING. The millisec timeout can have the following values:
Code Example