@@ -33,14 +33,25 @@ namespace mbed {
33
33
* Usage:
34
34
* @code
35
35
*
36
- * void f() {
37
- * // some code here
38
- * {
39
- * CriticalSectionLock lock;
40
- * // Code in this block will run with interrupts disabled
41
- * }
42
- * // interrupts will be restored to their previous state
36
+ * // RAII style usage
37
+ * unsigned int atomic_counter_increment(unsigned int &counter) {
38
+ * CriticalSectionLock lock;
39
+ * // Code in this block will run with interrupts disabled
40
+ * // Interrupts will be restored to their previous state automatically
41
+ * // at the end of function scope
42
+ * return ++counter;
43
43
* }
44
+ *
45
+ * // free locking usage
46
+ * unsigned int atomic_counter_decrement(unsigned int &counter) {
47
+ * CriticalSectionLock::enable();
48
+ * // Code in this block will run with interrupts disabled
49
+ * counter--;
50
+ * CriticalSectionLock::disable(); // need explicitly to disable critical section lock
51
+ * // interrupts will be restored to their previous state here
52
+ * return counter;
53
+ * }
54
+ *
44
55
* @endcode
45
56
*/
46
57
class CriticalSectionLock {
@@ -56,20 +67,40 @@ class CriticalSectionLock {
56
67
}
57
68
58
69
/* * Mark the start of a critical section
59
- *
70
+ *
60
71
*/
72
+ MBED_DEPRECATED_SINCE (" mbed-os-5.8" ,
73
+ " This function is inconsistent with RAII and is being removed in the future."
74
+ " Replaced by static function CriticalSectionLock::enable." )
61
75
void lock ()
62
76
{
63
77
core_util_critical_section_enter ();
64
78
}
65
79
66
80
/* * Mark the end of a critical section
67
- *
81
+ *
68
82
*/
83
+ MBED_DEPRECATED_SINCE (" mbed-os-5.8" ,
84
+ " This function is inconsistent with RAII and is being removed in the future."
85
+ " Replaced by static function CriticalSectionLock::disable." )
69
86
void unlock ()
70
87
{
71
88
core_util_critical_section_exit ();
72
89
}
90
+
91
+ /* * Mark the start of a critical section
92
+ */
93
+ static void enable ()
94
+ {
95
+ core_util_critical_section_enter ();
96
+ }
97
+
98
+ /* * Mark the end of a critical section
99
+ */
100
+ static void disable ()
101
+ {
102
+ core_util_critical_section_exit ();
103
+ }
73
104
};
74
105
75
106
/* *@}*/
0 commit comments