mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-01-10 06:48:50 -05:00
Updated FreeRTOS source code to 10.4.6. Moved FreeRTOS sources to the third-party directory. Added necessary changes to the CMake configuration. Split FreeRTOSConfig.h. From now, each board has its own. Added missing log headers. Minor refactor of the module-os cmake. Fixed stack overflows in bell application main and time service.
42 lines
924 B
C++
42 lines
924 B
C++
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "critical.hpp"
|
|
#include "LockGuard.hpp"
|
|
#include <macros.h>
|
|
#include <stdexcept>
|
|
|
|
namespace
|
|
{
|
|
[[nodiscard]] bool isOSRunning()
|
|
{
|
|
return xTaskGetSchedulerState() == taskSCHEDULER_RUNNING;
|
|
}
|
|
} // namespace
|
|
|
|
LockGuard::LockGuard(cpp_freertos::MutexStandard &mutex) : mutex(mutex)
|
|
{
|
|
if (not isOSRunning()) {
|
|
return;
|
|
}
|
|
if (isIRQ()) {
|
|
savedInterruptStatus = cpp_freertos::CriticalSection::EnterFromISR();
|
|
}
|
|
else if (!mutex.Lock()) {
|
|
throw std::runtime_error("LockGuard failed to lock mutex");
|
|
}
|
|
}
|
|
|
|
LockGuard::~LockGuard()
|
|
{
|
|
if (not isOSRunning()) {
|
|
return;
|
|
}
|
|
if (isIRQ()) {
|
|
cpp_freertos::CriticalSection::ExitFromISR(savedInterruptStatus);
|
|
}
|
|
else {
|
|
mutex.Unlock();
|
|
}
|
|
}
|