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