test

Committer:
elijahsj
Date:
Mon Nov 09 00:33:19 2020 -0500
Revision:
2:4364577b5ad8
Parent:
1:8a094db1347f
copied mbed library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elijahsj 1:8a094db1347f 1 /*
elijahsj 1:8a094db1347f 2 * PackageLicenseDeclared: Apache-2.0
elijahsj 1:8a094db1347f 3 * Copyright (c) 2017 ARM Limited
elijahsj 1:8a094db1347f 4 *
elijahsj 1:8a094db1347f 5 * Licensed under the Apache License, Version 2.0 (the "License");
elijahsj 1:8a094db1347f 6 * you may not use this file except in compliance with the License.
elijahsj 1:8a094db1347f 7 * You may obtain a copy of the License at
elijahsj 1:8a094db1347f 8 *
elijahsj 1:8a094db1347f 9 * http://www.apache.org/licenses/LICENSE-2.0
elijahsj 1:8a094db1347f 10 *
elijahsj 1:8a094db1347f 11 * Unless required by applicable law or agreed to in writing, software
elijahsj 1:8a094db1347f 12 * distributed under the License is distributed on an "AS IS" BASIS,
elijahsj 1:8a094db1347f 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
elijahsj 1:8a094db1347f 14 * See the License for the specific language governing permissions and
elijahsj 1:8a094db1347f 15 * limitations under the License.
elijahsj 1:8a094db1347f 16 */
elijahsj 1:8a094db1347f 17
elijahsj 1:8a094db1347f 18 #ifndef MBED_CRITICALSECTIONLOCK_H
elijahsj 1:8a094db1347f 19 #define MBED_CRITICALSECTIONLOCK_H
elijahsj 1:8a094db1347f 20
elijahsj 1:8a094db1347f 21 #include "platform/mbed_critical.h"
elijahsj 1:8a094db1347f 22
elijahsj 1:8a094db1347f 23 namespace mbed {
elijahsj 1:8a094db1347f 24
elijahsj 1:8a094db1347f 25 /** RAII object for disabling, then restoring, interrupt state
elijahsj 1:8a094db1347f 26 * Usage:
elijahsj 1:8a094db1347f 27 * @code
elijahsj 1:8a094db1347f 28 *
elijahsj 1:8a094db1347f 29 * void f() {
elijahsj 1:8a094db1347f 30 * // some code here
elijahsj 1:8a094db1347f 31 * {
elijahsj 1:8a094db1347f 32 * CriticalSectionLock lock;
elijahsj 1:8a094db1347f 33 * // Code in this block will run with interrupts disabled
elijahsj 1:8a094db1347f 34 * }
elijahsj 1:8a094db1347f 35 * // interrupts will be restored to their previous state
elijahsj 1:8a094db1347f 36 * }
elijahsj 1:8a094db1347f 37 * @endcode
elijahsj 1:8a094db1347f 38 */
elijahsj 1:8a094db1347f 39 class CriticalSectionLock {
elijahsj 1:8a094db1347f 40 public:
elijahsj 1:8a094db1347f 41 CriticalSectionLock()
elijahsj 1:8a094db1347f 42 {
elijahsj 1:8a094db1347f 43 core_util_critical_section_enter();
elijahsj 1:8a094db1347f 44 }
elijahsj 1:8a094db1347f 45
elijahsj 1:8a094db1347f 46 ~CriticalSectionLock()
elijahsj 1:8a094db1347f 47 {
elijahsj 1:8a094db1347f 48 core_util_critical_section_exit();
elijahsj 1:8a094db1347f 49 }
elijahsj 1:8a094db1347f 50
elijahsj 1:8a094db1347f 51 /** Mark the start of a critical section
elijahsj 1:8a094db1347f 52 *
elijahsj 1:8a094db1347f 53 */
elijahsj 1:8a094db1347f 54 void lock()
elijahsj 1:8a094db1347f 55 {
elijahsj 1:8a094db1347f 56 core_util_critical_section_enter();
elijahsj 1:8a094db1347f 57 }
elijahsj 1:8a094db1347f 58
elijahsj 1:8a094db1347f 59 /** Mark the end of a critical section
elijahsj 1:8a094db1347f 60 *
elijahsj 1:8a094db1347f 61 */
elijahsj 1:8a094db1347f 62 void unlock()
elijahsj 1:8a094db1347f 63 {
elijahsj 1:8a094db1347f 64 core_util_critical_section_exit();
elijahsj 1:8a094db1347f 65 }
elijahsj 1:8a094db1347f 66 };
elijahsj 1:8a094db1347f 67
elijahsj 1:8a094db1347f 68
elijahsj 1:8a094db1347f 69 } // namespace mbed
elijahsj 1:8a094db1347f 70
elijahsj 1:8a094db1347f 71 #endif