pico:
Also, since the original ATOMIC_BLOCK macros are actually based on a "for" loop under the hood to specify the code block, it would be theoretically possible to inadvertantly place a "break" or "continue" statement in such a block, and the compiler would not pick it up as out of place. Not a biggie in practice, but a bug yours doesn't suffer from.
Actually no. The macros don't use the third part of a for loop, which runs at the end of the oop but can be "break"d, but rather a gcc attribute that says to run this piece of code when this variable is destructed.
Also C++ doesn't support longjmp --- destructors aren't called. I'm pretty sure this wouldn't work (please note I have never used setjmp and am not bothering to look up the syntax ![]()
void setup() {
pinMode(13, OUTPUT);
if (setjmp()) {
digitalWrite(13, HIGH);
}
else {
AtomicBlock<Atomic_Force> a;
longjmp();
}
// Interrupts disabled
}