updated
Dependents: NSDL_HelloWorld_WiFi_K64_test
Fork of mbed-rtos by
rtos/Semaphore.h@6:350b53afb889, 2012-11-23 (annotated)
- Committer:
- emilmont
- Date:
- Fri Nov 23 09:57:31 2012 +0000
- Revision:
- 6:350b53afb889
- Child:
- 8:88a1a9c26ae3
Merge RTOS C++ API and RTX under the same library; Update RTX to version 4.60; Add proper Thread destructor;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 6:350b53afb889 | 1 | /* Copyright (c) 2012 mbed.org */ |
emilmont | 6:350b53afb889 | 2 | #ifndef SEMAPHORE_H |
emilmont | 6:350b53afb889 | 3 | #define SEMAPHORE_H |
emilmont | 6:350b53afb889 | 4 | |
emilmont | 6:350b53afb889 | 5 | #include <stdint.h> |
emilmont | 6:350b53afb889 | 6 | #include "cmsis_os.h" |
emilmont | 6:350b53afb889 | 7 | |
emilmont | 6:350b53afb889 | 8 | namespace rtos { |
emilmont | 6:350b53afb889 | 9 | |
emilmont | 6:350b53afb889 | 10 | /*! The Semaphore class is used to manage and protect access to a set of shared resources. */ |
emilmont | 6:350b53afb889 | 11 | class Semaphore { |
emilmont | 6:350b53afb889 | 12 | public: |
emilmont | 6:350b53afb889 | 13 | /*! Create and Initialize a Semaphore object used for managing resources. |
emilmont | 6:350b53afb889 | 14 | \param number of available resources; maximum index value is (count-1). |
emilmont | 6:350b53afb889 | 15 | */ |
emilmont | 6:350b53afb889 | 16 | Semaphore(int32_t count); |
emilmont | 6:350b53afb889 | 17 | |
emilmont | 6:350b53afb889 | 18 | /*! Wait until a Semaphore resource becomes available. |
emilmont | 6:350b53afb889 | 19 | \param millisec timeout value or 0 in case of no time-out. (default: osWaitForever). |
emilmont | 6:350b53afb889 | 20 | \return number of available tokens, or -1 in case of incorrect parameters |
emilmont | 6:350b53afb889 | 21 | */ |
emilmont | 6:350b53afb889 | 22 | int32_t wait(uint32_t millisec=osWaitForever); |
emilmont | 6:350b53afb889 | 23 | |
emilmont | 6:350b53afb889 | 24 | /*! Release a Semaphore resource that was obtain with Semaphore::wait. |
emilmont | 6:350b53afb889 | 25 | \return status code that indicates the execution status of the function. |
emilmont | 6:350b53afb889 | 26 | */ |
emilmont | 6:350b53afb889 | 27 | osStatus release(void); |
emilmont | 6:350b53afb889 | 28 | |
emilmont | 6:350b53afb889 | 29 | ~Semaphore(); |
emilmont | 6:350b53afb889 | 30 | |
emilmont | 6:350b53afb889 | 31 | private: |
emilmont | 6:350b53afb889 | 32 | osSemaphoreId _osSemaphoreId; |
emilmont | 6:350b53afb889 | 33 | osSemaphoreDef_t _osSemaphoreDef; |
emilmont | 6:350b53afb889 | 34 | #ifdef CMSIS_OS_RTX |
emilmont | 6:350b53afb889 | 35 | uint32_t _semaphore_data[2]; |
emilmont | 6:350b53afb889 | 36 | #endif |
emilmont | 6:350b53afb889 | 37 | }; |
emilmont | 6:350b53afb889 | 38 | |
emilmont | 6:350b53afb889 | 39 | } |
emilmont | 6:350b53afb889 | 40 | #endif |