Nicolas Borla / Mbed OS ROME2_Robot_Firmware
Committer:
boro
Date:
Mon Mar 16 13:12:31 2020 +0000
Revision:
0:4beb2ea291ec
a

Who changed what in which revision?

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