| 64 | |
| 65 | template<ptrdiff_t LeastMaxValue> |
| 66 | void CountingSemaphoreESP32<LeastMaxValue>::release(ptrdiff_t update) { |
| 67 | FL_ASSERT(update >= 0, "CountingSemaphoreESP32: release update must be non-negative"); |
| 68 | FL_ASSERT(mHandle != nullptr, "CountingSemaphoreESP32::release() called on null semaphore"); |
| 69 | |
| 70 | SemaphoreHandle_t handle = static_cast<SemaphoreHandle_t>(mHandle); |
| 71 | |
| 72 | // Release the semaphore 'update' times |
| 73 | for (ptrdiff_t i = 0; i < update; ++i) { |
| 74 | BaseType_t result = pdFALSE; |
| 75 | if (xPortInIsrContext()) { |
| 76 | BaseType_t higherPriorityTaskWoken = pdFALSE; |
| 77 | result = xSemaphoreGiveFromISR(handle, &higherPriorityTaskWoken); |
| 78 | if (higherPriorityTaskWoken == pdTRUE) { |
| 79 | portYIELD_FROM_ISR(); |
| 80 | } |
| 81 | } else { |
| 82 | result = xSemaphoreGive(handle); |
| 83 | } |
| 84 | |
| 85 | // If we fail to give, it means we would exceed the max value |
| 86 | if (result != pdTRUE) { |
| 87 | FL_ASSERT(false, "CountingSemaphoreESP32: release would exceed max value"); |
| 88 | break; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | template<ptrdiff_t LeastMaxValue> |
| 94 | void CountingSemaphoreESP32<LeastMaxValue>::acquire() { |
no outgoing calls
no test coverage detected