diff options
| author | Damien George <damien@micropython.org> | 2021-07-21 01:33:16 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2021-07-22 00:20:53 +1000 |
| commit | 6214fa3f9ecdfb146aaec09afc9d586e76257d5a (patch) | |
| tree | f6eeae0ab26d0def2994837146b666ba5c982276 | |
| parent | 2cfbe5bc0fe2c8ed24c6f35abbc82ef8415d17e4 (diff) | |
esp32/mphalport: Always yield at least once in delay_ms.
This helps the OS switch to and give other threads processing time during
the sleep. It also ensures that pending events are handled, even when
sleeping for 0ms.
Fixes issue #5344.
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | ports/esp32/mphalport.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/ports/esp32/mphalport.c b/ports/esp32/mphalport.c index e795b5c99..6e6fd26ef 100644 --- a/ports/esp32/mphalport.c +++ b/ports/esp32/mphalport.c @@ -142,14 +142,22 @@ void mp_hal_delay_ms(uint32_t ms) { uint64_t dt; uint64_t t0 = esp_timer_get_time(); for (;;) { + mp_handle_pending(true); + MICROPY_PY_USOCKET_EVENTS_HANDLER + MP_THREAD_GIL_EXIT(); uint64_t t1 = esp_timer_get_time(); dt = t1 - t0; if (dt + portTICK_PERIOD_MS * 1000 >= us) { // doing a vTaskDelay would take us beyond requested delay time + taskYIELD(); + MP_THREAD_GIL_ENTER(); + t1 = esp_timer_get_time(); + dt = t1 - t0; break; + } else { + ulTaskNotifyTake(pdFALSE, 1); + MP_THREAD_GIL_ENTER(); } - MICROPY_EVENT_POLL_HOOK - ulTaskNotifyTake(pdFALSE, 1); } if (dt < us) { // do the remaining delay accurately |
