mbed
Fork of mbed-dev by
Embed:
(wiki syntax)
Show/hide line numbers
CriticalSectionLock.h
00001 /* 00002 * PackageLicenseDeclared: Apache-2.0 00003 * Copyright (c) 2017 ARM Limited 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #ifndef MBED_CRITICALSECTIONLOCK_H 00019 #define MBED_CRITICALSECTIONLOCK_H 00020 00021 #include "platform/mbed_critical.h" 00022 #include "platform/mbed_toolchain.h" 00023 00024 namespace mbed { 00025 00026 /** \addtogroup platform */ 00027 /** @{*/ 00028 /** 00029 * \defgroup platform_CriticalSectionLock CriticalSectionLock functions 00030 * @{ 00031 */ 00032 00033 /** RAII object for disabling, then restoring, interrupt state 00034 * Usage: 00035 * @code 00036 * 00037 * void f() { 00038 * // some code here 00039 * { 00040 * CriticalSectionLock lock; 00041 * // Code in this block will run with interrupts disabled 00042 * } 00043 * // interrupts will be restored to their previous state 00044 * } 00045 * @endcode 00046 */ 00047 class CriticalSectionLock { 00048 public: 00049 CriticalSectionLock() 00050 { 00051 core_util_critical_section_enter(); 00052 } 00053 00054 ~CriticalSectionLock() 00055 { 00056 core_util_critical_section_exit(); 00057 } 00058 00059 /** Mark the start of a critical section 00060 * 00061 */ 00062 void lock() 00063 { 00064 core_util_critical_section_enter(); 00065 } 00066 00067 /** Mark the end of a critical section 00068 * 00069 */ 00070 void unlock() 00071 { 00072 core_util_critical_section_exit(); 00073 } 00074 }; 00075 00076 /**@}*/ 00077 00078 /**@}*/ 00079 00080 } // namespace mbed 00081 00082 #endif
Generated on Tue Jul 12 2022 18:02:50 by
1.7.2
