/* * utility_atomicscopeguard.hpp * * Created on: Mar 21, 2021 * Author: erki */ #ifndef SKULLC_UTILITY_ATOMICSCOPEGUARD_HPP_ #define SKULLC_UTILITY_ATOMICSCOPEGUARD_HPP_ #include namespace Utility { template struct AtomicScopeGuard { using hal = H; AtomicScopeGuard() { hal::disableInterrupts(); reentrancy_counter_++; } AtomicScopeGuard(const AtomicScopeGuard&) = delete; AtomicScopeGuard(AtomicScopeGuard&&) = delete; AtomicScopeGuard& operator=(const AtomicScopeGuard&) = delete; AtomicScopeGuard& operator=(AtomicScopeGuard&&) = delete; ~AtomicScopeGuard() { reentrancy_counter_--; if (!reentrancy_counter_) hal::enableInterrupts(); } private: static std::int32_t reentrancy_counter_; }; template std::int32_t AtomicScopeGuard::reentrancy_counter_ = 0; }// namespace Utility #endif /* SKULLC_UTILITY_ATOMICSCOPEGUARD_HPP_ */