|
ME507 Utility Library
0.2.1
Mechatronics Course Support Software for ARM/Arduino/FreeRTOS
|
Class which implements a mutex which can guard a resource. More...
#include <mutex.h>
Public Member Functions | |
| Mutex (TickType_t timeout=portMAX_DELAY) | |
| Create a mutex and save a handle to it. More... | |
| bool | take (void) |
| Take the mutex, preventing other tasks from using whatever resource the mutex protects. More... | |
| void | give (void) |
| Give back the mutex, allowing other tasks to access the resource protected by the mutex. | |
Protected Attributes | |
| SemaphoreHandle_t | handle |
| Handle to the FreeRTOS mutex being used. | |
| TickType_t | timeout |
| How many RTOS ticks to wait for the mutex. | |
Class which implements a mutex which can guard a resource.
A mutex (short for MUTual EXclusion) is used to ensure that two tasks don't use a resource at the same time. This is one method which can be used to prevent data corruption due to task switching. This class doesn't add functionality to the FreeRTOS mutex; it just simplifies the programming interface.
|
inline |
Create a mutex and save a handle to it.
A mutex must not be used within an interrupt service routine; there are ways to use queues to accomplish the same goal. See the FreeRTOS documentation for details.
| timeout | The number of RTOS ticks to wait for the mutex to become available if another task has it (default portMAX_DELAY which means wait forever) |
|
inline |
Take the mutex, preventing other tasks from using whatever resource the mutex protects.
true if the mutex was taken or false if we timed out