Skip to content
Snippets Groups Projects
Commit 1a5c8d10 authored by Damien George's avatar Damien George
Browse files

py/vm: Don't release the GIL if the scheduler is locked.

The scheduler being locked general means we are running a scheduled
function, and switching to another thread violates that, so don't switch in
such a case (even though we technically could).

And if we are running a scheduled function then we want to finish it ASAP,
so we shouldn't switch to another thread.

Furthermore, ports with threading enabled will lock the scheduler during a
hard IRQ, and this patch to the VM will make sure that threads are not
switched during a hard IRQ (which would crash the VM).
parent 231cfc84
Branches
No related tags found
No related merge requests found
...@@ -1301,9 +1301,15 @@ pending_exception_check: ...@@ -1301,9 +1301,15 @@ pending_exception_check:
#else #else
{ {
#endif #endif
#if MICROPY_ENABLE_SCHEDULER
// can only switch threads if the scheduler is unlocked
if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE)
#endif
{
MP_THREAD_GIL_EXIT(); MP_THREAD_GIL_EXIT();
MP_THREAD_GIL_ENTER(); MP_THREAD_GIL_ENTER();
} }
}
#endif #endif
} // for loop } // for loop
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment