t

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Wed Nov 08 13:50:44 2017 +0000
Revision:
178:d650f5d4c87a
Parent:
175:b96e65c34a4d
This updates the lib to the mbed lib v 155

Who changed what in which revision?

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