meshtastic-firmware/src/concurrency/Lock.cpp

39 wiersze
547 B
C++
Czysty Zwykły widok Historia

#include "Lock.h"
2023-01-21 13:34:29 +00:00
#include "configuration.h"
#include <cassert>
2020-09-04 22:03:22 +00:00
namespace concurrency
{
2020-09-04 22:03:22 +00:00
#ifdef HAS_FREE_RTOS
2022-01-24 18:39:17 +00:00
Lock::Lock() : handle(xSemaphoreCreateBinary())
{
assert(handle);
if (xSemaphoreGive(handle) == false) {
abort();
}
}
void Lock::lock()
{
if (xSemaphoreTake(handle, portMAX_DELAY) == false) {
abort();
}
}
void Lock::unlock()
{
if (xSemaphoreGive(handle) == false) {
abort();
}
}
2020-09-04 22:03:22 +00:00
#else
Lock::Lock() {}
void Lock::lock() {}
void Lock::unlock() {}
#endif
} // namespace concurrency