avr-classes
Public Member Functions | List of all members
AutomaticInterruptLock Class Reference

#include <automaticinterruptlock.h>

Public Member Functions

 AutomaticInterruptLock (void)
 
 ~AutomaticInterruptLock (void)
 

Detailed Description

Class that implements a lock mechanism by disabling the global interrupt flag. The previous state of SREG is stored and restored, so this lock can also be used if the interrupts are already disabled without accidentally enabling them.

Note
When the instance is created the global interrupt flag is cleared, when the instance is destroyed the flag is restored. The idea is to use this to lock an entire block scope. When you need to protect a fraction inside a block, consider using GlobalInterruptFlag::clear and GlobalInterruptFlag::restore manually.

Constructor & Destructor Documentation

◆ AutomaticInterruptLock()

AutomaticInterruptLock::AutomaticInterruptLock ( void  )
inline

Constructor, automatically shuts the lock by disabling the global interrupt flag.

◆ ~AutomaticInterruptLock()

AutomaticInterruptLock::~AutomaticInterruptLock ( void  )
inline

Destructor, automatically opens the lock by restoring the previous state of the global interrupt flag.