esp32/machine_uart: Release GIL for blocking reads.

If we're reading from an UART with a non-zero timeout, we can release the
GIL so that other threads/tasks may run while we are sleeping waiting for
data to arrive.

Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
pull/12236/head
Daniël van de Giessen 2022-11-23 14:20:58 +01:00
rodzic f8bd6778c8
commit 3cc3e4e032
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 9F0EF4D3441C8163
1 zmienionych plików z 9 dodań i 0 usunięć

Wyświetl plik

@ -472,8 +472,17 @@ STATIC mp_uint_t machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t siz
time_to_wait = pdMS_TO_TICKS(self->timeout);
}
bool release_gil = time_to_wait > 0;
if (release_gil) {
MP_THREAD_GIL_EXIT();
}
int bytes_read = uart_read_bytes(self->uart_num, buf_in, size, time_to_wait);
if (release_gil) {
MP_THREAD_GIL_ENTER();
}
if (bytes_read <= 0) {
*errcode = MP_EAGAIN;
return MP_STREAM_ERROR;