Mistake on this page?
Report an issue in GitHub or email us
CriticalSectionLock.h
1 /*
2  * Copyright (c) 2017 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef MBED_CRITICALSECTIONLOCK_H
19 #define MBED_CRITICALSECTIONLOCK_H
20 
21 #include "platform/mbed_critical.h"
22 #include "platform/mbed_toolchain.h"
23 
24 namespace mbed {
25 
26 /** \addtogroup platform */
27 /** @{*/
28 /**
29  * \defgroup platform_CriticalSectionLock CriticalSectionLock functions
30  * @{
31  */
32 
33 /** RAII object for disabling, then restoring, interrupt state
34  * Usage:
35  * @code
36  *
37  * // RAII style usage
38  * unsigned int atomic_counter_increment(unsigned int &counter) {
39  * CriticalSectionLock lock;
40  * // Code in this block will run with interrupts disabled
41  * // Interrupts will be restored to their previous state automatically
42  * // at the end of function scope
43  * return ++counter;
44  * }
45  *
46  * // free locking usage
47  * unsigned int atomic_counter_decrement(unsigned int &counter) {
48  * CriticalSectionLock::enable();
49  * // Code in this block will run with interrupts disabled
50  * counter--;
51  * CriticalSectionLock::disable(); // need explicitly to disable critical section lock
52  * // interrupts will be restored to their previous state here
53  * return counter;
54  * }
55  *
56  * @endcode
57  */
59 public:
61  {
63  }
64 
66  {
68  }
69 
70  /** Mark the start of a critical section
71  * @deprecated This function is inconsistent with RAII and is being removed in the future. Replaced by static function CriticalSectionLock::enable.
72  *
73  */
74  MBED_DEPRECATED_SINCE("mbed-os-5.8",
75  "This function is inconsistent with RAII and is being removed in the future."
76  "Replaced by static function CriticalSectionLock::enable.")
77  void lock()
78  {
80  }
81 
82  /** Mark the end of a critical section
83  * @deprecated This function is inconsistent with RAII and is being removed in the future. Replaced by static function CriticalSectionLock::enable.
84  *
85  */
86  MBED_DEPRECATED_SINCE("mbed-os-5.8",
87  "This function is inconsistent with RAII and is being removed in the future."
88  "Replaced by static function CriticalSectionLock::disable.")
89  void unlock()
90  {
92  }
93 
94  /** Mark the start of a critical section
95  */
96  static void enable()
97  {
99  }
100 
101  /** Mark the end of a critical section
102  */
103  static void disable()
104  {
106  }
107 };
108 
109 /**@}*/
110 
111 /**@}*/
112 
113 } // namespace mbed
114 
115 #endif
void core_util_critical_section_exit(void)
Mark the end of a critical section.
void lock()
Mark the start of a critical section.
void core_util_critical_section_enter(void)
Mark the start of a critical section.
static void enable()
Mark the start of a critical section.
static void disable()
Mark the end of a critical section.
RAII object for disabling, then restoring, interrupt state Usage:
Definition: AnalogIn.h:28
void unlock()
Mark the end of a critical section.
#define MBED_DEPRECATED_SINCE(D, M)
MBED_DEPRECATED("message string") Mark a function declaration as deprecated, if it used then a warnin...
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.