unix: Allow the GIL to be enabled.

The unix port can now be built with the GIL enabled, by passing
MICROPY_PY_THREAD_GIL=1 on the make command line.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2025-07-13 22:35:53 +10:00
parent 92193112bf
commit b6460df721
5 changed files with 15 additions and 2 deletions

View File

@@ -132,7 +132,11 @@ ifeq ($(MICROPY_PY_SOCKET),1)
CFLAGS += -DMICROPY_PY_SOCKET=1
endif
ifeq ($(MICROPY_PY_THREAD),1)
ifeq ($(MICROPY_PY_THREAD_GIL),1)
CFLAGS += -DMICROPY_PY_THREAD=1 -DMICROPY_PY_THREAD_GIL=1
else
CFLAGS += -DMICROPY_PY_THREAD=1 -DMICROPY_PY_THREAD_GIL=0
endif
LDFLAGS += $(LIBPTHREAD)
endif

View File

@@ -137,6 +137,9 @@ typedef long mp_off_t;
#define MICROPY_STACKLESS_STRICT (0)
#endif
// Recursive mutex is needed when threading is enabled, regardless of GIL setting.
#define MICROPY_PY_THREAD_RECURSIVE_MUTEX (MICROPY_PY_THREAD)
// Implementation of the machine module.
#define MICROPY_PY_MACHINE_INCLUDEFILE "ports/unix/modmachine.c"

View File

@@ -13,6 +13,7 @@ MICROPY_PY_BTREE = 1
# _thread module using pthreads
MICROPY_PY_THREAD = 1
MICROPY_PY_THREAD_GIL = 0
# Subset of CPython termios module
MICROPY_PY_TERMIOS = 1

View File

@@ -40,7 +40,12 @@
//
// Note that we don't delay for the full TIMEOUT_MS, as execution
// can't be woken from the delay.
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) mp_hal_delay_us(500)
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) \
do { \
MP_THREAD_GIL_EXIT(); \
mp_hal_delay_us(500); \
MP_THREAD_GIL_ENTER(); \
} while (0)
void mp_hal_set_interrupt_char(char c);

View File

@@ -29,7 +29,7 @@
// Send raise KeyboardInterrupt directly from the signal handler rather than
// scheduling it into the VM.
#define MICROPY_ASYNC_KBD_INTR (1)
#define MICROPY_ASYNC_KBD_INTR (!MICROPY_PY_THREAD_GIL)
// Enable helpers for printing debugging information.
#ifndef MICROPY_DEBUG_PRINTERS