1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#pragma once #include <cstdint> struct critical_section { uint32_t primask; critical_section() { asm volatile("mrs %0, primask" : "=r" (primask)); asm volatile("cpsid i"); asm volatile("dmb"); } ~critical_section() { asm volatile("dmb"); asm volatile("msr primask, %0" :: "r" (primask)); } };