| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title CriticalSectionStub.cpp | ||
| 3 | // \author tumbar | ||
| 4 | // \brief Stub CriticalSection implementation for Linux/test builds | ||
| 5 | // | ||
| 6 | // This file is compiled for Linux/test builds so that components depending on | ||
| 7 | // fprime-samd_Drv_Types can link under native unit testing without the SAMD21 | ||
| 8 | // CMSIS intrinsics (__disable_irq/__get_PRIMASK/etc.). For SAMD21 target | ||
| 9 | // builds, CriticalSection.cpp is used instead. | ||
| 10 | // | ||
| 11 | // Unit tests run single-threaded with no ISRs, so a critical section is a | ||
| 12 | // no-op: nesting is still reference-counted for parity with the real | ||
| 13 | // implementation, but no interrupts exist to disable. | ||
| 14 | // ====================================================================== | ||
| 15 | |||
| 16 | #include "Fw/FPrimeBasicTypes.hpp" | ||
| 17 | #include "fprime-samd/Drv/Types/CriticalSection.hpp" | ||
| 18 | |||
| 19 | namespace Samd21 { | ||
| 20 | |||
| 21 | //! Depth of the currently-held critical section nesting | ||
| 22 | static U32 s_critical_section_counter = 0; | ||
| 23 | |||
| 24 | ✗ | void CriticalSection::enter() { | |
| 25 | ✗ | s_critical_section_counter++; | |
| 26 | ✗ | } | |
| 27 | |||
| 28 | ✗ | void CriticalSection::leave() { | |
| 29 | ✗ | if (s_critical_section_counter > 0) { | |
| 30 | ✗ | s_critical_section_counter--; | |
| 31 | } | ||
| 32 | ✗ | } | |
| 33 | |||
| 34 | ✗ | CriticalSection::CriticalSection() { | |
| 35 | ✗ | CriticalSection::enter(); | |
| 36 | ✗ | } | |
| 37 | |||
| 38 | ✗ | CriticalSection::~CriticalSection() { | |
| 39 | ✗ | CriticalSection::leave(); | |
| 40 | ✗ | } | |
| 41 | |||
| 42 | } // namespace Samd21 | ||
| 43 |