summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid Lechner <david@pybricks.com>2020-01-23 14:11:13 -0600
committerDamien George <damien.p.george@gmail.com>2020-01-26 23:31:27 +1100
commitd89ed3e62b152174c3eb5c96713e9b983b11f7ed (patch)
treeff1f05e7ea7ef5f25395fab9dd9249ab55dc3d9d
parentbc3499f0103abcae39ad048bb42a518a665b8497 (diff)
downloadmicropython-d89ed3e62b152174c3eb5c96713e9b983b11f7ed.tar.gz
micropython-d89ed3e62b152174c3eb5c96713e9b983b11f7ed.zip
unix/unix_mphal: Add compile check for incompatible GIL+ASYNC_KBD_INTR.
It is not safe to enable MICROPY_ASYNC_KBD_INTR and MICROPY_PY_THREAD_GIL at the same time. This will trigger a compiler error to ensure that it is not possible to make this mistake.
-rw-r--r--ports/unix/unix_mphal.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/ports/unix/unix_mphal.c b/ports/unix/unix_mphal.c
index 3e14409efb..25d1b022db 100644
--- a/ports/unix/unix_mphal.c
+++ b/ports/unix/unix_mphal.c
@@ -41,6 +41,11 @@
STATIC void sighandler(int signum) {
if (signum == SIGINT) {
#if MICROPY_ASYNC_KBD_INTR
+ #if MICROPY_PY_THREAD_GIL
+ // Since signals can occur at any time, we may not be holding the GIL when
+ // this callback is called, so it is not safe to raise an exception here
+ #error "MICROPY_ASYNC_KBD_INTR and MICROPY_PY_THREAD_GIL are not compatible"
+ #endif
mp_obj_exception_clear_traceback(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)));
sigset_t mask;
sigemptyset(&mask);