Files
MuditaOS/module-os/LockGuard.cpp
Mateusz Grzegorzek a60e27fa4b [EGD-4593] Dump logs to file on timeout
- Dump logs to file every 10 sec.
- max file size is 50 MB
  (after reaching it, no more logs will be logged),
- Add `LockGuard` with locking mechanism
  supporting IRQ and use it in `Logger`.
- Fix minor style issues in `Logger`.
- Add `mount_user_lfs_partition.py` script for mounting LFS on Linux FS
  in order to get `MuditaOS.log` file from `user` partition
2021-03-17 16:33:02 +01:00

28 lines
678 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>
LockGuard::LockGuard(cpp_freertos::MutexStandard& mutex) : mutex(mutex)
{
if (isIRQ()) {
savedInterruptStatus = cpp_freertos::CriticalSection::EnterFromISR();
}
else if(!mutex.Lock()) {
throw std::runtime_error("LockGuard failed to lock mutex");
}
}
LockGuard::~LockGuard()
{
if (isIRQ()) {
cpp_freertos::CriticalSection::ExitFromISR(savedInterruptStatus);
}
else {
mutex.Unlock();
}
}