Semaphore.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 SEMAPHORE_H |
PA | 0:7ae810ca8a42 | 3 | #define SEMAPHORE_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 Semaphore class is used to manage and protect access to a set of shared resources. */ |
PA | 0:7ae810ca8a42 | 11 | class Semaphore { |
PA | 0:7ae810ca8a42 | 12 | public: |
PA | 0:7ae810ca8a42 | 13 | /*! Create and Initialize a Semaphore object used for managing resources. |
PA | 0:7ae810ca8a42 | 14 | \param number of available resources; maximum index value is (count-1). |
PA | 0:7ae810ca8a42 | 15 | */ |
PA | 0:7ae810ca8a42 | 16 | Semaphore(int32_t count); |
PA | 0:7ae810ca8a42 | 17 | |
PA | 0:7ae810ca8a42 | 18 | /*! Wait until a Semaphore resource 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 number of available tokens, or -1 in case of incorrect parameters |
PA | 0:7ae810ca8a42 | 21 | */ |
PA | 0:7ae810ca8a42 | 22 | int32_t wait(uint32_t millisec=osWaitForever); |
PA | 0:7ae810ca8a42 | 23 | |
PA | 0:7ae810ca8a42 | 24 | /*! Release a Semaphore resource that was obtain with Semaphore::wait. |
PA | 0:7ae810ca8a42 | 25 | \return status code that indicates the execution status of the function. |
PA | 0:7ae810ca8a42 | 26 | */ |
PA | 0:7ae810ca8a42 | 27 | osStatus release(void); |
PA | 0:7ae810ca8a42 | 28 | |
PA | 0:7ae810ca8a42 | 29 | private: |
PA | 0:7ae810ca8a42 | 30 | osSemaphoreId _osSemaphoreId; |
PA | 0:7ae810ca8a42 | 31 | osSemaphoreDef_t _osSemaphoreDef; |
PA | 0:7ae810ca8a42 | 32 | #ifdef CMSIS_OS_RTX |
PA | 0:7ae810ca8a42 | 33 | uint32_t _semaphore_data[2]; |
PA | 0:7ae810ca8a42 | 34 | #endif |
PA | 0:7ae810ca8a42 | 35 | }; |
PA | 0:7ae810ca8a42 | 36 | |
PA | 0:7ae810ca8a42 | 37 | } |
PA | 0:7ae810ca8a42 | 38 | #endif |