mbed library sources. Supersedes mbed-src.
Fork of mbed-dev by
platform/CriticalSectionLock.h@180:d79f997829d6, 2017-12-18 (annotated)
- Committer:
- Anythingconnected
- Date:
- Mon Dec 18 10:14:27 2017 +0000
- Revision:
- 180:d79f997829d6
- Parent:
- 178:79309dc6340a
Getting byte by byte read to work
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 174:b96e65c34a4d | 1 | /* |
AnnaBridge | 174:b96e65c34a4d | 2 | * PackageLicenseDeclared: Apache-2.0 |
AnnaBridge | 174:b96e65c34a4d | 3 | * Copyright (c) 2017 ARM Limited |
AnnaBridge | 174:b96e65c34a4d | 4 | * |
AnnaBridge | 174:b96e65c34a4d | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
AnnaBridge | 174:b96e65c34a4d | 6 | * you may not use this file except in compliance with the License. |
AnnaBridge | 174:b96e65c34a4d | 7 | * You may obtain a copy of the License at |
AnnaBridge | 174:b96e65c34a4d | 8 | * |
AnnaBridge | 174:b96e65c34a4d | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
AnnaBridge | 174:b96e65c34a4d | 10 | * |
AnnaBridge | 174:b96e65c34a4d | 11 | * Unless required by applicable law or agreed to in writing, software |
AnnaBridge | 174:b96e65c34a4d | 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
AnnaBridge | 174:b96e65c34a4d | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
AnnaBridge | 174:b96e65c34a4d | 14 | * See the License for the specific language governing permissions and |
AnnaBridge | 174:b96e65c34a4d | 15 | * limitations under the License. |
AnnaBridge | 174:b96e65c34a4d | 16 | */ |
AnnaBridge | 174:b96e65c34a4d | 17 | |
AnnaBridge | 174:b96e65c34a4d | 18 | #ifndef MBED_CRITICALSECTIONLOCK_H |
AnnaBridge | 174:b96e65c34a4d | 19 | #define MBED_CRITICALSECTIONLOCK_H |
AnnaBridge | 174:b96e65c34a4d | 20 | |
AnnaBridge | 174:b96e65c34a4d | 21 | #include "platform/mbed_critical.h" |
AnnaBridge | 174:b96e65c34a4d | 22 | |
AnnaBridge | 174:b96e65c34a4d | 23 | namespace mbed { |
AnnaBridge | 174:b96e65c34a4d | 24 | |
AnnaBridge | 178:79309dc6340a | 25 | /** \addtogroup platform */ |
AnnaBridge | 178:79309dc6340a | 26 | /** @{*/ |
AnnaBridge | 178:79309dc6340a | 27 | /** |
AnnaBridge | 178:79309dc6340a | 28 | * \defgroup platform_CriticalSectionLock CriticalSectionLock functions |
AnnaBridge | 178:79309dc6340a | 29 | * @{ |
AnnaBridge | 178:79309dc6340a | 30 | */ |
AnnaBridge | 178:79309dc6340a | 31 | |
AnnaBridge | 174:b96e65c34a4d | 32 | /** RAII object for disabling, then restoring, interrupt state |
AnnaBridge | 174:b96e65c34a4d | 33 | * Usage: |
AnnaBridge | 174:b96e65c34a4d | 34 | * @code |
AnnaBridge | 174:b96e65c34a4d | 35 | * |
AnnaBridge | 174:b96e65c34a4d | 36 | * void f() { |
AnnaBridge | 174:b96e65c34a4d | 37 | * // some code here |
AnnaBridge | 174:b96e65c34a4d | 38 | * { |
AnnaBridge | 174:b96e65c34a4d | 39 | * CriticalSectionLock lock; |
AnnaBridge | 174:b96e65c34a4d | 40 | * // Code in this block will run with interrupts disabled |
AnnaBridge | 174:b96e65c34a4d | 41 | * } |
AnnaBridge | 174:b96e65c34a4d | 42 | * // interrupts will be restored to their previous state |
AnnaBridge | 174:b96e65c34a4d | 43 | * } |
AnnaBridge | 174:b96e65c34a4d | 44 | * @endcode |
AnnaBridge | 174:b96e65c34a4d | 45 | */ |
AnnaBridge | 174:b96e65c34a4d | 46 | class CriticalSectionLock { |
AnnaBridge | 174:b96e65c34a4d | 47 | public: |
AnnaBridge | 174:b96e65c34a4d | 48 | CriticalSectionLock() |
AnnaBridge | 174:b96e65c34a4d | 49 | { |
AnnaBridge | 174:b96e65c34a4d | 50 | core_util_critical_section_enter(); |
AnnaBridge | 174:b96e65c34a4d | 51 | } |
AnnaBridge | 174:b96e65c34a4d | 52 | |
AnnaBridge | 174:b96e65c34a4d | 53 | ~CriticalSectionLock() |
AnnaBridge | 174:b96e65c34a4d | 54 | { |
AnnaBridge | 174:b96e65c34a4d | 55 | core_util_critical_section_exit(); |
AnnaBridge | 174:b96e65c34a4d | 56 | } |
AnnaBridge | 174:b96e65c34a4d | 57 | |
AnnaBridge | 174:b96e65c34a4d | 58 | /** Mark the start of a critical section |
AnnaBridge | 174:b96e65c34a4d | 59 | * |
AnnaBridge | 174:b96e65c34a4d | 60 | */ |
AnnaBridge | 174:b96e65c34a4d | 61 | void lock() |
AnnaBridge | 174:b96e65c34a4d | 62 | { |
AnnaBridge | 174:b96e65c34a4d | 63 | core_util_critical_section_enter(); |
AnnaBridge | 174:b96e65c34a4d | 64 | } |
AnnaBridge | 174:b96e65c34a4d | 65 | |
AnnaBridge | 174:b96e65c34a4d | 66 | /** Mark the end of a critical section |
AnnaBridge | 174:b96e65c34a4d | 67 | * |
AnnaBridge | 174:b96e65c34a4d | 68 | */ |
AnnaBridge | 174:b96e65c34a4d | 69 | void unlock() |
AnnaBridge | 174:b96e65c34a4d | 70 | { |
AnnaBridge | 174:b96e65c34a4d | 71 | core_util_critical_section_exit(); |
AnnaBridge | 174:b96e65c34a4d | 72 | } |
AnnaBridge | 174:b96e65c34a4d | 73 | }; |
AnnaBridge | 174:b96e65c34a4d | 74 | |
AnnaBridge | 178:79309dc6340a | 75 | /**@}*/ |
AnnaBridge | 178:79309dc6340a | 76 | |
AnnaBridge | 178:79309dc6340a | 77 | /**@}*/ |
AnnaBridge | 174:b96e65c34a4d | 78 | |
AnnaBridge | 174:b96e65c34a4d | 79 | } // namespace mbed |
AnnaBridge | 174:b96e65c34a4d | 80 | |
AnnaBridge | 174:b96e65c34a4d | 81 | #endif |