dhgdh
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
mbd_os/TESTS/mbedmicro-rtos-mbed/threads/LockGuard.h@9:6bb35cef007d, 2016-10-22 (annotated)
- Committer:
- cyberjoey
- Date:
- Sat Oct 22 01:31:58 2016 +0000
- Revision:
- 9:6bb35cef007d
- Parent:
- 1:55a6170b404f
WORKING
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nexpaq | 1:55a6170b404f | 1 | /* |
nexpaq | 1:55a6170b404f | 2 | * Copyright (c) 2013-2016, ARM Limited, All Rights Reserved |
nexpaq | 1:55a6170b404f | 3 | * SPDX-License-Identifier: Apache-2.0 |
nexpaq | 1:55a6170b404f | 4 | * |
nexpaq | 1:55a6170b404f | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
nexpaq | 1:55a6170b404f | 6 | * not use this file except in compliance with the License. |
nexpaq | 1:55a6170b404f | 7 | * You may obtain a copy of the License at |
nexpaq | 1:55a6170b404f | 8 | * |
nexpaq | 1:55a6170b404f | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
nexpaq | 1:55a6170b404f | 10 | * |
nexpaq | 1:55a6170b404f | 11 | * Unless required by applicable law or agreed to in writing, software |
nexpaq | 1:55a6170b404f | 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
nexpaq | 1:55a6170b404f | 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
nexpaq | 1:55a6170b404f | 14 | * See the License for the specific language governing permissions and |
nexpaq | 1:55a6170b404f | 15 | * limitations under the License. |
nexpaq | 1:55a6170b404f | 16 | */ |
nexpaq | 1:55a6170b404f | 17 | |
nexpaq | 1:55a6170b404f | 18 | #ifndef MBEDMICRO_RTOS_MBED_THREADS_LOCK_GUARD |
nexpaq | 1:55a6170b404f | 19 | #define MBEDMICRO_RTOS_MBED_THREADS_LOCK_GUARD |
nexpaq | 1:55a6170b404f | 20 | |
nexpaq | 1:55a6170b404f | 21 | #include <rtos.h> |
nexpaq | 1:55a6170b404f | 22 | |
nexpaq | 1:55a6170b404f | 23 | /** |
nexpaq | 1:55a6170b404f | 24 | * RAII mutex locker. |
nexpaq | 1:55a6170b404f | 25 | * The mutex pass in the constructor will be locked for the lifetime of |
nexpaq | 1:55a6170b404f | 26 | * the LockGuard instance. |
nexpaq | 1:55a6170b404f | 27 | */ |
nexpaq | 1:55a6170b404f | 28 | class LockGuard { |
nexpaq | 1:55a6170b404f | 29 | public: |
nexpaq | 1:55a6170b404f | 30 | /** |
nexpaq | 1:55a6170b404f | 31 | * Construct a LockGuard instance and ackire ownership of mutex in input. |
nexpaq | 1:55a6170b404f | 32 | * @param mutex The mutex to ackire ownership of. |
nexpaq | 1:55a6170b404f | 33 | */ |
nexpaq | 1:55a6170b404f | 34 | LockGuard(rtos::Mutex& mutex) : _mutex(mutex) { |
nexpaq | 1:55a6170b404f | 35 | _mutex.lock(); |
nexpaq | 1:55a6170b404f | 36 | } |
nexpaq | 1:55a6170b404f | 37 | |
nexpaq | 1:55a6170b404f | 38 | /** |
nexpaq | 1:55a6170b404f | 39 | * Destruct the lock and release the inner mutex. |
nexpaq | 1:55a6170b404f | 40 | */ |
nexpaq | 1:55a6170b404f | 41 | ~LockGuard() { |
nexpaq | 1:55a6170b404f | 42 | _mutex.unlock(); |
nexpaq | 1:55a6170b404f | 43 | } |
nexpaq | 1:55a6170b404f | 44 | |
nexpaq | 1:55a6170b404f | 45 | private: |
nexpaq | 1:55a6170b404f | 46 | LockGuard(const LockGuard&); |
nexpaq | 1:55a6170b404f | 47 | LockGuard& operator=(const LockGuard&); |
nexpaq | 1:55a6170b404f | 48 | rtos::Mutex& _mutex; |
nexpaq | 1:55a6170b404f | 49 | }; |
nexpaq | 1:55a6170b404f | 50 | |
nexpaq | 1:55a6170b404f | 51 | #endif /* MBEDMICRO_RTOS_MBED_THREADS_LOCK_GUARD */ |