WrappedSemaphore.h 666 B

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