mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 03:30:14 +01:00
unix: Release GIL during all system calls.
Addition of GIL EXIT/ENTER pairs are: - modos: release the GIL during system calls. CPython does this as well. - moduselect: release the GIL during the poll() syscall. This call can be blocking, so it is important to allow other threads to run at this time. - modusocket: release the GIL during system calls. Many of these calls can be blocking, so it is important to allow other threads to run. - unix_mphal: release the GIL during the read and write syscalls in mp_hal_stdin_rx_chr and mp_hal_stdout_tx_strn. If we don't do this threads are blocked when the REPL or the builtin input function are used. - file, main, mpconfigport.h: release GIL during syscalls in built-in functions that could block.
This commit is contained in:
committed by
Damien George
parent
96716b46e1
commit
fee7e5617f
@@ -31,6 +31,7 @@
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "py/mphal.h"
|
||||
#include "py/mpthread.h"
|
||||
#include "py/runtime.h"
|
||||
#include "extmod/misc.h"
|
||||
|
||||
@@ -160,7 +161,9 @@ int mp_hal_stdin_rx_chr(void) {
|
||||
} else {
|
||||
main_term:;
|
||||
#endif
|
||||
MP_THREAD_GIL_EXIT();
|
||||
int ret = read(0, &c, 1);
|
||||
MP_THREAD_GIL_ENTER();
|
||||
if (ret == 0) {
|
||||
c = 4; // EOF, ctrl-D
|
||||
} else if (c == '\n') {
|
||||
@@ -173,7 +176,9 @@ int mp_hal_stdin_rx_chr(void) {
|
||||
}
|
||||
|
||||
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
|
||||
MP_THREAD_GIL_EXIT();
|
||||
int ret = write(1, str, len);
|
||||
MP_THREAD_GIL_ENTER();
|
||||
mp_uos_dupterm_tx_strn(str, len);
|
||||
(void)ret; // to suppress compiler warning
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user