Mistake on this page?
Report an issue in GitHub or email us
CriticalSectionLock.h
1 /*
2  * Copyright (c) 2017-2019 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_toolchain.h"
22 
23 namespace mbed {
24 /** \addtogroup platform-public-api */
25 /** @{*/
26 /**
27  * \defgroup platform_CriticalSectionLock CriticalSectionLock functions
28  * @{
29  */
30 
31 /** RAII object for disabling, then restoring, interrupt state
32  * Usage:
33  * @code
34  *
35  * // RAII style usage
36  * unsigned int atomic_counter_increment(unsigned int &counter) {
37  * CriticalSectionLock lock;
38  * // Code in this block will run with interrupts disabled
39  * // Interrupts will be restored to their previous state automatically
40  * // at the end of function scope
41  * return ++counter;
42  * }
43  *
44  * // free locking usage
45  * unsigned int atomic_counter_decrement(unsigned int &counter) {
46  * CriticalSectionLock::enable();
47  * // Code in this block will run with interrupts disabled
48  * counter--;
49  * CriticalSectionLock::disable(); // need explicitly to disable critical section lock
50  * // interrupts will be restored to their previous state here
51  * return counter;
52  * }
53  *
54  * @endcode
55  */
57 public:
59 
61 
62  /** Mark the start of a critical section
63  * @deprecated This function is inconsistent with RAII and is being removed in the future. Replaced by static function CriticalSectionLock::enable.
64  *
65  */
66  MBED_DEPRECATED_SINCE("mbed-os-5.8",
67  "This function is inconsistent with RAII and is being removed in the future."
68  "Replaced by static function CriticalSectionLock::enable.")
69  void lock();
70 
71  /** Mark the end of a critical section
72  * @deprecated This function is inconsistent with RAII and is being removed in the future. Replaced by static function CriticalSectionLock::enable.
73  *
74  */
75  MBED_DEPRECATED_SINCE("mbed-os-5.8",
76  "This function is inconsistent with RAII and is being removed in the future."
77  "Replaced by static function CriticalSectionLock::disable.")
78  void unlock();
79 
80  /** Mark the start of a critical section
81  */
82  static void enable();
83 
84  /** Mark the end of a critical section
85  */
86  static void disable();
87 };
88 
89 /**@}*/
90 
91 /**@}*/
92 
93 } // namespace mbed
94 
95 #endif
void lock()
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:
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.