Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbd_os/TESTS/mbedmicro-rtos-mbed/threads/LockGuard.h@0:eafc3fd41f75, 2016-09-20 (annotated)
- Committer:
- bryantaylor
- Date:
- Tue Sep 20 21:26:12 2016 +0000
- Revision:
- 0:eafc3fd41f75
hackathon
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bryantaylor | 0:eafc3fd41f75 | 1 | /* |
bryantaylor | 0:eafc3fd41f75 | 2 | * Copyright (c) 2013-2016, ARM Limited, All Rights Reserved |
bryantaylor | 0:eafc3fd41f75 | 3 | * SPDX-License-Identifier: Apache-2.0 |
bryantaylor | 0:eafc3fd41f75 | 4 | * |
bryantaylor | 0:eafc3fd41f75 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
bryantaylor | 0:eafc3fd41f75 | 6 | * not use this file except in compliance with the License. |
bryantaylor | 0:eafc3fd41f75 | 7 | * You may obtain a copy of the License at |
bryantaylor | 0:eafc3fd41f75 | 8 | * |
bryantaylor | 0:eafc3fd41f75 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
bryantaylor | 0:eafc3fd41f75 | 10 | * |
bryantaylor | 0:eafc3fd41f75 | 11 | * Unless required by applicable law or agreed to in writing, software |
bryantaylor | 0:eafc3fd41f75 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
bryantaylor | 0:eafc3fd41f75 | 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
bryantaylor | 0:eafc3fd41f75 | 14 | * See the License for the specific language governing permissions and |
bryantaylor | 0:eafc3fd41f75 | 15 | * limitations under the License. |
bryantaylor | 0:eafc3fd41f75 | 16 | */ |
bryantaylor | 0:eafc3fd41f75 | 17 | |
bryantaylor | 0:eafc3fd41f75 | 18 | #ifndef MBEDMICRO_RTOS_MBED_THREADS_LOCK_GUARD |
bryantaylor | 0:eafc3fd41f75 | 19 | #define MBEDMICRO_RTOS_MBED_THREADS_LOCK_GUARD |
bryantaylor | 0:eafc3fd41f75 | 20 | |
bryantaylor | 0:eafc3fd41f75 | 21 | #include <rtos.h> |
bryantaylor | 0:eafc3fd41f75 | 22 | |
bryantaylor | 0:eafc3fd41f75 | 23 | /** |
bryantaylor | 0:eafc3fd41f75 | 24 | * RAII mutex locker. |
bryantaylor | 0:eafc3fd41f75 | 25 | * The mutex pass in the constructor will be locked for the lifetime of |
bryantaylor | 0:eafc3fd41f75 | 26 | * the LockGuard instance. |
bryantaylor | 0:eafc3fd41f75 | 27 | */ |
bryantaylor | 0:eafc3fd41f75 | 28 | class LockGuard { |
bryantaylor | 0:eafc3fd41f75 | 29 | public: |
bryantaylor | 0:eafc3fd41f75 | 30 | /** |
bryantaylor | 0:eafc3fd41f75 | 31 | * Construct a LockGuard instance and ackire ownership of mutex in input. |
bryantaylor | 0:eafc3fd41f75 | 32 | * @param mutex The mutex to ackire ownership of. |
bryantaylor | 0:eafc3fd41f75 | 33 | */ |
bryantaylor | 0:eafc3fd41f75 | 34 | LockGuard(rtos::Mutex& mutex) : _mutex(mutex) { |
bryantaylor | 0:eafc3fd41f75 | 35 | _mutex.lock(); |
bryantaylor | 0:eafc3fd41f75 | 36 | } |
bryantaylor | 0:eafc3fd41f75 | 37 | |
bryantaylor | 0:eafc3fd41f75 | 38 | /** |
bryantaylor | 0:eafc3fd41f75 | 39 | * Destruct the lock and release the inner mutex. |
bryantaylor | 0:eafc3fd41f75 | 40 | */ |
bryantaylor | 0:eafc3fd41f75 | 41 | ~LockGuard() { |
bryantaylor | 0:eafc3fd41f75 | 42 | _mutex.unlock(); |
bryantaylor | 0:eafc3fd41f75 | 43 | } |
bryantaylor | 0:eafc3fd41f75 | 44 | |
bryantaylor | 0:eafc3fd41f75 | 45 | private: |
bryantaylor | 0:eafc3fd41f75 | 46 | LockGuard(const LockGuard&); |
bryantaylor | 0:eafc3fd41f75 | 47 | LockGuard& operator=(const LockGuard&); |
bryantaylor | 0:eafc3fd41f75 | 48 | rtos::Mutex& _mutex; |
bryantaylor | 0:eafc3fd41f75 | 49 | }; |
bryantaylor | 0:eafc3fd41f75 | 50 | |
bryantaylor | 0:eafc3fd41f75 | 51 | #endif /* MBEDMICRO_RTOS_MBED_THREADS_LOCK_GUARD */ |