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