Brandon Donohue / Mbed 2 deprecated IoTBattleship

Dependencies:   mbed

Committer:
bdonohue
Date:
Sat Apr 28 22:07:24 2018 +0000
Revision:
0:912c221cc186
working final ver

Who changed what in which revision?

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