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  */
64  static void enable();
65 
66  /** Mark the end of a critical section
67  */
68  static void disable();
69 };
70 
71 /**@}*/
72 
73 /**@}*/
74 
75 } // namespace mbed
76 
77 #endif
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: ATHandler.h:46
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.