Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CriticalSectionLock.h Source File

CriticalSectionLock.h

00001 /*
00002  * Copyright (c) 2017-2019 ARM Limited
00003  * SPDX-License-Identifier: Apache-2.0
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_toolchain.h"
00022 
00023 namespace mbed {
00024 /** \addtogroup platform-public-api */
00025 /** @{*/
00026 /**
00027  * \defgroup platform_CriticalSectionLock CriticalSectionLock functions
00028  * @{
00029  */
00030 
00031 /** RAII object for disabling, then restoring, interrupt state
00032   * Usage:
00033   * @code
00034   *
00035   * // RAII style usage
00036   * unsigned int atomic_counter_increment(unsigned int &counter) {
00037   *     CriticalSectionLock lock;
00038   *     // Code in this block will run with interrupts disabled
00039   *     // Interrupts will be restored to their previous state automatically
00040   *     // at the end of function scope
00041   *     return ++counter;
00042   * }
00043   *
00044   * // free locking usage
00045   * unsigned int atomic_counter_decrement(unsigned int &counter) {
00046   *     CriticalSectionLock::enable();
00047   *     // Code in this block will run with interrupts disabled
00048   *     counter--;
00049   *     CriticalSectionLock::disable(); // need explicitly to disable critical section lock
00050   *     // interrupts will be restored to their previous state here
00051   *     return counter;
00052   * }
00053   *
00054   * @endcode
00055   */
00056 class CriticalSectionLock {
00057 public:
00058     CriticalSectionLock();
00059 
00060     ~CriticalSectionLock();
00061 
00062     /** Mark the start of a critical section
00063      *  @deprecated This function is inconsistent with RAII and is being removed in the future. Replaced by static function CriticalSectionLock::enable.
00064      *
00065      */
00066     MBED_DEPRECATED_SINCE("mbed-os-5.8",
00067                           "This function is inconsistent with RAII and is being removed in the future."
00068                           "Replaced by static function CriticalSectionLock::enable.")
00069     void lock();
00070 
00071     /** Mark the end of a critical section
00072      *  @deprecated This function is inconsistent with RAII and is being removed in the future. Replaced by static function CriticalSectionLock::enable.
00073      *
00074      */
00075     MBED_DEPRECATED_SINCE("mbed-os-5.8",
00076                           "This function is inconsistent with RAII and is being removed in the future."
00077                           "Replaced by static function CriticalSectionLock::disable.")
00078     void unlock();
00079 
00080     /** Mark the start of a critical section
00081      */
00082     static void enable();
00083 
00084     /** Mark the end of a critical section
00085      */
00086     static void disable();
00087 };
00088 
00089 /**@}*/
00090 
00091 /**@}*/
00092 
00093 } // namespace mbed
00094 
00095 #endif