Files
firmware/src/concurrency/Lock.cpp
Chloe Bethel 4e6418b635 Don't use assert() with side effects in a couple more places (#7009)
* Don't use assert for Lock

* Don't use assert for MQTT messages

* Split assert in getMacAddr to always run the function

---------

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
2025-06-12 19:55:35 -05:00

39 lines
547 B
C++

#include "Lock.h"
#include "configuration.h"
#include <cassert>
namespace concurrency
{
#ifdef HAS_FREE_RTOS
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();
}
}
#else
Lock::Lock() {}
void Lock::lock() {}
void Lock::unlock() {}
#endif
} // namespace concurrency