Implement freertos mutex wrapper
This commit is contained in:
parent
27ed5d0663
commit
3ff75471f6
2 changed files with 39 additions and 0 deletions
20
Firmware/src/FreeRTOS/Mutex.cpp
Normal file
20
Firmware/src/FreeRTOS/Mutex.cpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#include "Mutex.h"
|
||||||
|
#include <etl/utility.h>
|
||||||
|
|
||||||
|
freertos::Mutex::Mutex() : handle{xSemaphoreCreateMutex()} {}
|
||||||
|
freertos::Mutex::Mutex(Mutex &&other) noexcept {
|
||||||
|
handle = etl::move(other.handle);
|
||||||
|
}
|
||||||
|
freertos::Mutex::~Mutex() { vSemaphoreDelete(handle); }
|
||||||
|
auto freertos::Mutex::operator=(const Mutex &&other) noexcept -> Mutex & {
|
||||||
|
handle = etl::move(other.handle);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
auto freertos::Mutex::lock(TickType_t timeout) -> bool{
|
||||||
|
BaseType_t success = xSemaphoreTake(handle, timeout);
|
||||||
|
return success == pdTRUE ? true : false;
|
||||||
|
}
|
||||||
|
auto freertos::Mutex::unlock() -> bool {
|
||||||
|
BaseType_t success = xSemaphoreGive(handle);
|
||||||
|
return success == pdTRUE ? true : false;
|
||||||
|
}
|
19
Firmware/src/FreeRTOS/Mutex.h
Normal file
19
Firmware/src/FreeRTOS/Mutex.h
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#pragma once
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
namespace freertos {
|
||||||
|
class Mutex {
|
||||||
|
public:
|
||||||
|
Mutex();
|
||||||
|
Mutex(const Mutex &other) = delete;
|
||||||
|
Mutex(Mutex &&other) noexcept;
|
||||||
|
~Mutex();
|
||||||
|
Mutex &operator=(const Mutex &other) = delete;
|
||||||
|
Mutex &operator=(const Mutex &&other) noexcept;
|
||||||
|
bool lock(TickType_t timeout = portMAX_DELAY);
|
||||||
|
bool unlock();
|
||||||
|
|
||||||
|
private:
|
||||||
|
SemaphoreHandle_t handle;
|
||||||
|
};
|
||||||
|
} // namespace freertos
|
Loading…
Reference in a new issue