| 136 | template<ptrdiff_t LeastMaxValue> |
| 137 | template<class Rep, class Period> |
| 138 | bool CountingSemaphoreESP32<LeastMaxValue>::try_acquire_for( |
| 139 | const std::chrono::duration<Rep, Period>& rel_time) { // okay std namespace |
| 140 | |
| 141 | if (mHandle == nullptr) { |
| 142 | return false; |
| 143 | } |
| 144 | |
| 145 | // Convert duration to FreeRTOS ticks |
| 146 | auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(rel_time); // okay std namespace |
| 147 | if (ms.count() <= 0) { |
| 148 | return try_acquire(); |
| 149 | } |
| 150 | TickType_t ticks = pdMS_TO_TICKS(ms.count()); |
| 151 | if (ticks == 0) { |
| 152 | ticks = 1; |
| 153 | } |
| 154 | |
| 155 | SemaphoreHandle_t handle = static_cast<SemaphoreHandle_t>(mHandle); |
| 156 | BaseType_t result = xSemaphoreTake(handle, ticks); |
| 157 | |
| 158 | return (result == pdTRUE); |
| 159 | } |
| 160 | |
| 161 | template<ptrdiff_t LeastMaxValue> |
| 162 | template<class Clock, class Duration> |