Alan Ffrench / Mbed 2 deprecated Experiment_2_5

Dependencies:   mbed

Committer:
alanffrench
Date:
Wed Jul 29 18:51:38 2020 +0000
Revision:
0:52468b19aa21
Threads

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alanffrench 0:52468b19aa21 1 /* mbed Microcontroller Library
alanffrench 0:52468b19aa21 2 * Copyright (c) 2006-2012 ARM Limited
alanffrench 0:52468b19aa21 3 *
alanffrench 0:52468b19aa21 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
alanffrench 0:52468b19aa21 5 * of this software and associated documentation files (the "Software"), to deal
alanffrench 0:52468b19aa21 6 * in the Software without restriction, including without limitation the rights
alanffrench 0:52468b19aa21 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
alanffrench 0:52468b19aa21 8 * copies of the Software, and to permit persons to whom the Software is
alanffrench 0:52468b19aa21 9 * furnished to do so, subject to the following conditions:
alanffrench 0:52468b19aa21 10 *
alanffrench 0:52468b19aa21 11 * The above copyright notice and this permission notice shall be included in
alanffrench 0:52468b19aa21 12 * all copies or substantial portions of the Software.
alanffrench 0:52468b19aa21 13 *
alanffrench 0:52468b19aa21 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
alanffrench 0:52468b19aa21 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
alanffrench 0:52468b19aa21 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
alanffrench 0:52468b19aa21 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
alanffrench 0:52468b19aa21 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
alanffrench 0:52468b19aa21 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
alanffrench 0:52468b19aa21 20 * SOFTWARE.
alanffrench 0:52468b19aa21 21 */
alanffrench 0:52468b19aa21 22 #ifndef MUTEX_H
alanffrench 0:52468b19aa21 23 #define MUTEX_H
alanffrench 0:52468b19aa21 24
alanffrench 0:52468b19aa21 25 #include <stdint.h>
alanffrench 0:52468b19aa21 26 #include "cmsis_os.h"
alanffrench 0:52468b19aa21 27
alanffrench 0:52468b19aa21 28 namespace rtos {
alanffrench 0:52468b19aa21 29
alanffrench 0:52468b19aa21 30 /** The Mutex class is used to synchronise the execution of threads.
alanffrench 0:52468b19aa21 31 This is for example used to protect access to a shared resource.
alanffrench 0:52468b19aa21 32 */
alanffrench 0:52468b19aa21 33 class Mutex {
alanffrench 0:52468b19aa21 34 public:
alanffrench 0:52468b19aa21 35 /** Create and Initialize a Mutex object */
alanffrench 0:52468b19aa21 36 Mutex();
alanffrench 0:52468b19aa21 37
alanffrench 0:52468b19aa21 38 /** Wait until a Mutex becomes available.
alanffrench 0:52468b19aa21 39 @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever)
alanffrench 0:52468b19aa21 40 @return status code that indicates the execution status of the function.
alanffrench 0:52468b19aa21 41 */
alanffrench 0:52468b19aa21 42 osStatus lock(uint32_t millisec=osWaitForever);
alanffrench 0:52468b19aa21 43
alanffrench 0:52468b19aa21 44 /** Try to lock the mutex, and return immediately
alanffrench 0:52468b19aa21 45 @return true if the mutex was acquired, false otherwise.
alanffrench 0:52468b19aa21 46 */
alanffrench 0:52468b19aa21 47 bool trylock();
alanffrench 0:52468b19aa21 48
alanffrench 0:52468b19aa21 49 /** Unlock the mutex that has previously been locked by the same thread
alanffrench 0:52468b19aa21 50 @return status code that indicates the execution status of the function.
alanffrench 0:52468b19aa21 51 */
alanffrench 0:52468b19aa21 52 osStatus unlock();
alanffrench 0:52468b19aa21 53
alanffrench 0:52468b19aa21 54 ~Mutex();
alanffrench 0:52468b19aa21 55
alanffrench 0:52468b19aa21 56 private:
alanffrench 0:52468b19aa21 57 osMutexId _osMutexId;
alanffrench 0:52468b19aa21 58 osMutexDef_t _osMutexDef;
alanffrench 0:52468b19aa21 59 #ifdef CMSIS_OS_RTX
alanffrench 0:52468b19aa21 60 int32_t _mutex_data[3];
alanffrench 0:52468b19aa21 61 #endif
alanffrench 0:52468b19aa21 62 };
alanffrench 0:52468b19aa21 63
alanffrench 0:52468b19aa21 64 }
alanffrench 0:52468b19aa21 65 #endif