Dave Lu / Mbed 2 deprecated FYDP

Dependencies:   mbed

Fork of FYDP_Final2 by Dave Lu

Committer:
tntmarket
Date:
Wed Mar 25 11:44:05 2015 +0000
Revision:
8:3d5a84b897be
Parent:
mbed/mbed-rtos/rtos/Mutex.h@0:21019d94ad33
lift folders

Who changed what in which revision?

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