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