Denislam Valeev / Mbed OS Nucleo_rtos_basic
Committer:
valeyev
Date:
Tue Mar 13 07:17:50 2018 +0000
Revision:
0:e056ac8fecf8
looking for...

Who changed what in which revision?

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