WrappedSemaphore.h 583 B

123456789101112131415161718192021222324252627282930313233
  1. #ifndef WRAPPEDSEMAPHORE_H
  2. #define WRAPPEDSEMAPHORE_H
  3. #ifdef ESP_PLATFORM
  4. #include "freertos/FreeRTOS.h"
  5. #include "freertos/semphr.h"
  6. #elif __APPLE__
  7. #include <dispatch/dispatch.h>
  8. #else
  9. #include <time.h>
  10. #include <semaphore.h>
  11. #endif
  12. class WrappedSemaphore
  13. {
  14. private:
  15. #ifdef ESP_PLATFORM
  16. xSemaphoreHandle semaphoreHandle;
  17. #elif __APPLE__
  18. dispatch_semaphore_t semaphoreHandle;
  19. #else
  20. sem_t semaphoreHandle;
  21. #endif
  22. public:
  23. WrappedSemaphore(int maxVal = 200);
  24. ~WrappedSemaphore();
  25. int wait();
  26. int twait(long milliseconds = 10);
  27. void give();
  28. };
  29. #endif