diff options
| author | David Lechner <david@pybricks.com> | 2020-01-24 11:50:31 -0600 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2020-01-26 23:27:40 +1100 |
| commit | bc3499f0103abcae39ad048bb42a518a665b8497 (patch) | |
| tree | cba45dd6ad8b95101bb5edac93f2d4971f20b647 | |
| parent | 62537a18e3743a040e8b673686665f27f7504ca8 (diff) | |
windows/windows_mphal: Release GIL during system calls.
This releases the GIL during syscalls that could block.
| -rw-r--r-- | ports/windows/windows_mphal.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/ports/windows/windows_mphal.c b/ports/windows/windows_mphal.c index 1ec8e27d6..6de888085 100644 --- a/ports/windows/windows_mphal.c +++ b/ports/windows/windows_mphal.c @@ -27,6 +27,7 @@ #include "py/mpstate.h" #include "py/mphal.h" +#include "py/mpthread.h" #include <sys/time.h> #include <windows.h> @@ -194,10 +195,14 @@ int mp_hal_stdin_rx_chr(void) { // poll until key which we handle is pressed assure_stdin_handle(); + BOOL status; DWORD num_read; INPUT_RECORD rec; for (;;) { - if (!ReadConsoleInput(std_in, &rec, 1, &num_read) || !num_read) { + MP_THREAD_GIL_EXIT(); + status = ReadConsoleInput(std_in, &rec, 1, &num_read) + MP_THREAD_GIL_ENTER(); + if (!status || !num_read) { return CHAR_CTRL_C; // EOF, ctrl-D } if (rec.EventType != KEY_EVENT || !rec.Event.KeyEvent.bKeyDown) { // only want key down events @@ -217,7 +222,9 @@ int mp_hal_stdin_rx_chr(void) { } void mp_hal_stdout_tx_strn(const char *str, size_t len) { + MP_THREAD_GIL_EXIT(); write(1, str, len); + MP_THREAD_GIL_ENTER(); } void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) { |
