Scoped Interrupt Lock (RAII)

Medium C++ Concurrency Asked at ARM
Solve this problem

Write a C++ guard class that disables interrupts on construction and restores the previous state on destruction, so a critical section cannot leak interrupts disabled on an early return.

Constraints

  • Must save and restore the prior mask, not blindly re-enable.
  • Copy and move must be deleted.
  • No heap allocation, no exceptions.
  • Use the provided disable_irq/restore_irq/save_irq_state hooks.
  • Nesting two guards must leave interrupts disabled until the outer one exits.
Starter codeC++
1#include <cstdint>2 3extern uint32_t save_irq_state();4extern void disable_irq();5extern void restore_irq(uint32_t state);6 7class InterruptLock {8    // TODO9};