| Age | Commit message (Collapse) | Author |
|
This introduces a new macro to get the main thread and uses it to ensure
that asynchronous exceptions such as KeyboardInterrupt (CTRL+C) are only
scheduled on the main thread. This is more deterministic than being
scheduled on a random thread and is more in line with CPython that only
allow signal handlers to run on the main thread.
Fixes issue #7026.
Signed-off-by: David Lechner <david@pybricks.com>
|
|
This moves mp_pending_exception from mp_state_vm_t to mp_state_thread_t.
This allows exceptions to be scheduled on a specific thread.
Signed-off-by: David Lechner <david@pybricks.com>
|
|
This was missed in commit 7cbf826a9575e18ce1b7fe11b0f0997509153260.
Signed-off-by: Damien George <damien@micropython.org>
|
|
So that a port can "wake up" when there is work to do.
Signed-off-by: Damien George <damien@micropython.org>
|
|
To match mp_sched_exception() and mp_sched_schedule().
Signed-off-by: Damien George <damien@micropython.org>
|
|
This helper is added to properly set a pending exception, to mirror
mp_sched_schedule(), which schedules a function.
Signed-off-by: Damien George <damien@micropython.org>
|
|
So they are guaranteed to be inlined within functions like
mp_sched_schedule which may be located in a special memory region.
|
|
So ports can put it in a special memory section if needed.
|
|
And add a test that shows how this can happen when multiple threads are
accessing the scheduler, which fails if atomic sections are not used.
|
|
Because the atomic section starts after checking whether the scheduler
state is pending, it's possible it can become a different state by the time
the atomic section starts.
This is especially likely on ports where MICROPY_BEGIN_ATOMIC_SECTION is
implemented with a mutex (i.e. it might block), but the race exists
regardless, i.e. if a context switch occurs between those two lines.
|
|
This is a more logical place to clear the KeyboardInterrupt traceback,
right before it is set as a pending exception. The clearing is also
optimised from a function call to a simple store of NULL.
|
|
Functions like mp_keyboard_interrupt() may need to be called from an IRQ
handler and may need to be in a special memory section, so provide a
generic wrapping macro for a port to do this. The macro name is chosen to
be MICROPY_WRAP_<function name in uppercase> so that (in the future with
more wrappers) each function could potentially be handled separately.
|
|
This function is tightly coupled to the state and behaviour of the
scheduler, and is a core part of the runtime: to schedule a pending
exception. So move it there.
|
|
Previous behaviour is when this argument is set to "true", in which case
the function will raise any pending exception. Setting it to "false" will
cancel any pending exception.
|
|
Behaviour was changed from stack to queue in
8977c7eb581f5d06500edb1ea29aea5cbda04f28, and this updates variable names
to match. Also updates other references (docs, error messages).
|
|
This means the schedule operates on a first-in, first-executed manner
rather than the current last-in, first executed.
|
|
|