WrappedSemaphore.cpp 701 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "WrappedSemaphore.h"
  2. /**
  3. * Platform semaphopre implementation for the esp-idf.
  4. */
  5. using namespace bell;
  6. WrappedSemaphore::WrappedSemaphore(int count)
  7. {
  8. semaphoreHandle = xSemaphoreCreateCounting(count, 0);
  9. }
  10. WrappedSemaphore::~WrappedSemaphore()
  11. {
  12. vSemaphoreDelete(semaphoreHandle);
  13. }
  14. int WrappedSemaphore::wait()
  15. {
  16. if (xSemaphoreTake(semaphoreHandle, portMAX_DELAY) == pdTRUE) {
  17. return 0;
  18. }
  19. return 1;
  20. }
  21. int WrappedSemaphore::twait(long milliseconds)
  22. {
  23. if (xSemaphoreTake(semaphoreHandle, milliseconds / portTICK_PERIOD_MS) == pdTRUE) {
  24. return 0;
  25. }
  26. return 1;
  27. }
  28. void WrappedSemaphore::give()
  29. {
  30. xSemaphoreGive(semaphoreHandle);
  31. }