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