RTOS lib used for Eurobot 2012
Mutex.h@1:b270f864114f, 2019-08-01 (annotated)
- Committer:
- eembed
- Date:
- Thu Aug 01 07:49:38 2019 +0000
- Revision:
- 1:b270f864114f
- Parent:
- 0:e477ba491a3b
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
narshu | 0:e477ba491a3b | 1 | /* Copyright (c) 2012 mbed.org */ |
narshu | 0:e477ba491a3b | 2 | #ifndef MUTEX_H |
narshu | 0:e477ba491a3b | 3 | #define MUTEX_H |
narshu | 0:e477ba491a3b | 4 | |
narshu | 0:e477ba491a3b | 5 | #include <stdint.h> |
narshu | 0:e477ba491a3b | 6 | #include "cmsis_os.h" |
narshu | 0:e477ba491a3b | 7 | |
narshu | 0:e477ba491a3b | 8 | namespace rtos { |
narshu | 0:e477ba491a3b | 9 | |
narshu | 0:e477ba491a3b | 10 | /*! The Mutex class is used to synchronise the execution of threads. |
narshu | 0:e477ba491a3b | 11 | This is for example used to protect access to a shared resource. |
narshu | 0:e477ba491a3b | 12 | */ |
narshu | 0:e477ba491a3b | 13 | class Mutex { |
narshu | 0:e477ba491a3b | 14 | public: |
narshu | 0:e477ba491a3b | 15 | /*! Create and Initialize a Mutex object */ |
narshu | 0:e477ba491a3b | 16 | Mutex(); |
narshu | 0:e477ba491a3b | 17 | |
narshu | 0:e477ba491a3b | 18 | /*! Wait until a Mutex becomes available. |
narshu | 0:e477ba491a3b | 19 | \param millisec timeout value or 0 in case of no time-out. (default: osWaitForever) |
narshu | 0:e477ba491a3b | 20 | \return status code that indicates the execution status of the function. |
narshu | 0:e477ba491a3b | 21 | */ |
narshu | 0:e477ba491a3b | 22 | osStatus lock(uint32_t millisec=osWaitForever); |
narshu | 0:e477ba491a3b | 23 | |
narshu | 0:e477ba491a3b | 24 | /*! Try to lock the mutex, and return immediately |
narshu | 0:e477ba491a3b | 25 | \return true if the mutex was acquired, false otherwise. |
narshu | 0:e477ba491a3b | 26 | */ |
narshu | 0:e477ba491a3b | 27 | bool trylock(); |
narshu | 0:e477ba491a3b | 28 | |
narshu | 0:e477ba491a3b | 29 | /*! Unlock the mutex that has previously been locked by the same thread |
narshu | 0:e477ba491a3b | 30 | \return status code that indicates the execution status of the function. |
narshu | 0:e477ba491a3b | 31 | */ |
narshu | 0:e477ba491a3b | 32 | osStatus unlock(); |
narshu | 0:e477ba491a3b | 33 | |
narshu | 0:e477ba491a3b | 34 | private: |
narshu | 0:e477ba491a3b | 35 | osMutexId _osMutexId; |
narshu | 0:e477ba491a3b | 36 | osMutexDef_t _osMutexDef; |
narshu | 0:e477ba491a3b | 37 | #ifdef CMSIS_OS_RTX |
narshu | 0:e477ba491a3b | 38 | int32_t _mutex_data[3]; |
narshu | 0:e477ba491a3b | 39 | #endif |
narshu | 0:e477ba491a3b | 40 | }; |
narshu | 0:e477ba491a3b | 41 | |
narshu | 0:e477ba491a3b | 42 | } |
narshu | 0:e477ba491a3b | 43 | #endif |