nkjnm

Dependencies:   MAX44000 nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Committer:
nitsshukla
Date:
Fri Nov 04 12:06:04 2016 +0000
Revision:
7:3a65ef12ba31
Parent:
1:55a6170b404f
kghj;

Who changed what in which revision?

UserRevisionLine numberNew 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_SYNCHRONIZED_INTEGRAL
nexpaq 1:55a6170b404f 19 #define MBEDMICRO_RTOS_MBED_THREADS_SYNCHRONIZED_INTEGRAL
nexpaq 1:55a6170b404f 20
nexpaq 1:55a6170b404f 21 #include <rtos.h>
nexpaq 1:55a6170b404f 22 #include "LockGuard.h"
nexpaq 1:55a6170b404f 23
nexpaq 1:55a6170b404f 24 /**
nexpaq 1:55a6170b404f 25 * Thread safe wrapper for integral types.
nexpaq 1:55a6170b404f 26 * @tparam T type of the integral
nexpaq 1:55a6170b404f 27 */
nexpaq 1:55a6170b404f 28 template<typename T>
nexpaq 1:55a6170b404f 29 class SynchronizedIntegral {
nexpaq 1:55a6170b404f 30 public:
nexpaq 1:55a6170b404f 31 SynchronizedIntegral(T value) : _mutex(), _value(value) { }
nexpaq 1:55a6170b404f 32
nexpaq 1:55a6170b404f 33 // preincrement operator
nexpaq 1:55a6170b404f 34 T operator++() {
nexpaq 1:55a6170b404f 35 LockGuard lock(_mutex);
nexpaq 1:55a6170b404f 36 return ++_value;
nexpaq 1:55a6170b404f 37 }
nexpaq 1:55a6170b404f 38
nexpaq 1:55a6170b404f 39 // predecrement operator
nexpaq 1:55a6170b404f 40 T operator--() {
nexpaq 1:55a6170b404f 41 LockGuard lock(_mutex);
nexpaq 1:55a6170b404f 42 return --_value;
nexpaq 1:55a6170b404f 43 }
nexpaq 1:55a6170b404f 44
nexpaq 1:55a6170b404f 45 // post increment operator
nexpaq 1:55a6170b404f 46 T operator++(int) {
nexpaq 1:55a6170b404f 47 LockGuard lock(_mutex);
nexpaq 1:55a6170b404f 48 return _value++;
nexpaq 1:55a6170b404f 49 }
nexpaq 1:55a6170b404f 50
nexpaq 1:55a6170b404f 51 // post decrement operator
nexpaq 1:55a6170b404f 52 T operator--(int) {
nexpaq 1:55a6170b404f 53 LockGuard lock(_mutex);
nexpaq 1:55a6170b404f 54 return _value--;
nexpaq 1:55a6170b404f 55 }
nexpaq 1:55a6170b404f 56
nexpaq 1:55a6170b404f 57 // conversion operator, used also for <,>,<=,>=,== and !=
nexpaq 1:55a6170b404f 58 operator T() const {
nexpaq 1:55a6170b404f 59 LockGuard lock(_mutex);
nexpaq 1:55a6170b404f 60 return _value;
nexpaq 1:55a6170b404f 61 }
nexpaq 1:55a6170b404f 62
nexpaq 1:55a6170b404f 63 // access to the internal mutex
nexpaq 1:55a6170b404f 64 rtos::Mutex& internal_mutex() {
nexpaq 1:55a6170b404f 65 return _mutex;
nexpaq 1:55a6170b404f 66 }
nexpaq 1:55a6170b404f 67
nexpaq 1:55a6170b404f 68 private:
nexpaq 1:55a6170b404f 69 mutable rtos::Mutex _mutex;
nexpaq 1:55a6170b404f 70 T _value;
nexpaq 1:55a6170b404f 71 };
nexpaq 1:55a6170b404f 72
nexpaq 1:55a6170b404f 73 #endif /* MBEDMICRO_RTOS_MBED_THREADS_SYNCHRONIZED_INTEGRAL */