Semaphore.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* Copyright (c) 2012 mbed.org */
  2. #ifndef SEMAPHORE_H
  3. #define SEMAPHORE_H
  4. #include <stdint.h>
  5. #include "cmsis_os.h"
  6. namespace rtos {
  7. /*! The Semaphore class is used to manage and protect access to a set of shared resources. */
  8. class Semaphore {
  9. public:
  10. /*! Create and Initialize a Semaphore object used for managing resources.
  11. \param number of available resources; maximum index value is (count-1).
  12. */
  13. Semaphore(int32_t count);
  14. /*! Wait until a Semaphore resource becomes available.
  15. \param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
  16. \return number of available tokens, or -1 in case of incorrect parameters
  17. */
  18. int32_t wait(uint32_t millisec=osWaitForever);
  19. /*! Release a Semaphore resource that was obtain with Semaphore::wait.
  20. \return status code that indicates the execution status of the function.
  21. */
  22. osStatus release(void);
  23. private:
  24. osSemaphoreId _osSemaphoreId;
  25. osSemaphoreDef_t _osSemaphoreDef;
  26. #ifdef CMSIS_OS_RTX
  27. uint32_t _semaphore_data[2];
  28. #endif
  29. };
  30. }
  31. #endif