Disables then re-enables interrupts based on variable scope. Ensures you don't forget to re-enable interrupts. Use Wisely!

Files at this revision

API Documentation at this revision

Comitter:
Tomo2k
Date:
Wed Apr 23 10:16:56 2014 +0000
Commit message:
IntDisabler class

Changed in this revision

intdisabler.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r cd6400023513 intdisabler.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/intdisabler.h	Wed Apr 23 10:16:56 2014 +0000
@@ -0,0 +1,27 @@
+/* (C) 2014 Richard Thompson (Tomo2k)
+This software is Apache 2.0 licenced for this to be reused.
+
+That said, it's trivial and rather obvious!
+*/
+#pragma once
+
+#include "mbed.h"
+
+//! Disable then Enable interrupts using variable scope.
+//! Ensures always re-enabled regardless of method exit
+class IntDisabler
+{
+public:
+    //! Disable Interrupts
+    IntDisabler() {
+        __disable_irq();
+    }
+    //! Enables Interrupts on destruction
+    ~IntDisabler() {
+        __enable_irq();
+    }
+private:
+    // Disable copy
+    IntDisabler & operator=(const IntDisabler&);
+    IntDisabler(const IntDisabler &);
+};