The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Revision:
165:d1b4690b3f8b
Parent:
161:aa5281ff4a02
Child:
170:e95d10626187
--- a/platform/CriticalSectionLock.h	Tue Mar 20 16:15:49 2018 +0000
+++ b/platform/CriticalSectionLock.h	Thu Apr 19 14:31:27 2018 +0100
@@ -34,14 +34,25 @@
   * Usage:
   * @code
   *
-  * void f() {
-  *     // some code here
-  *     {
-  *         CriticalSectionLock lock;
-  *         // Code in this block will run with interrupts disabled
-  *     }
-  *     // interrupts will be restored to their previous state
+  * // RAII style usage
+  * unsigned int atomic_counter_increment(unsigned int &counter) {
+  *     CriticalSectionLock lock;
+  *     // Code in this block will run with interrupts disabled
+  *     // Interrupts will be restored to their previous state automatically
+  *     // at the end of function scope
+  *     return ++counter;
   * }
+  *
+  * // free locking usage
+  * unsigned int atomic_counter_decrement(unsigned int &counter) {
+  *     CriticalSectionLock::enable();
+  *     // Code in this block will run with interrupts disabled
+  *     counter--;
+  *     CriticalSectionLock::disable(); // need explicitly to disable critical section lock
+  *     // interrupts will be restored to their previous state here
+  *     return counter;
+  * }
+  *
   * @endcode
   */
 class CriticalSectionLock {
@@ -57,20 +68,42 @@
     }
 
     /** Mark the start of a critical section
-     *     
+     *  @deprecated This function is inconsistent with RAII and is being removed in the future. Replaced by static function CriticalSectionLock::enable.
+     *
      */
+    MBED_DEPRECATED_SINCE("mbed-os-5.8",
+            "This function is inconsistent with RAII and is being removed in the future."
+            "Replaced by static function CriticalSectionLock::enable.")
     void lock()
     {
         core_util_critical_section_enter();
     }
 
     /** Mark the end of a critical section
-     *     
+     *  @deprecated This function is inconsistent with RAII and is being removed in the future. Replaced by static function CriticalSectionLock::enable.
+     *
      */
+    MBED_DEPRECATED_SINCE("mbed-os-5.8",
+            "This function is inconsistent with RAII and is being removed in the future."
+            "Replaced by static function CriticalSectionLock::disable.")
     void unlock()
     {
         core_util_critical_section_exit();
     }
+
+    /** Mark the start of a critical section
+     */
+    static void enable()
+    {
+        core_util_critical_section_enter();
+    }
+
+    /** Mark the end of a critical section
+     */
+    static void disable()
+    {
+        core_util_critical_section_exit();
+    }
 };
 
 /**@}*/