py/modthread: Move thread state initialisation to shared function.

Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
This commit is contained in:
Daniël van de Giessen
2024-02-28 12:41:41 +01:00
parent 678707c8b0
commit bc424ddc41
3 changed files with 29 additions and 23 deletions

View File

@@ -160,10 +160,7 @@ STATIC void *thread_entry(void *args_in) {
thread_entry_args_t *args = (thread_entry_args_t *)args_in;
mp_state_thread_t ts;
mp_thread_set_state(&ts);
mp_stack_set_top(&ts + 1); // need to include ts in root-pointer scan
mp_stack_set_limit(args->stack_size);
mp_thread_init_state(&ts, args->stack_size, args->dict_locals, args->dict_globals);
#if MICROPY_ENABLE_PYSTACK
// TODO threading and pystack is not fully supported, for now just make a small stack
@@ -171,16 +168,6 @@ STATIC void *thread_entry(void *args_in) {
mp_pystack_init(mini_pystack, &mini_pystack[128]);
#endif
// The GC starts off unlocked on this thread.
ts.gc_lock_depth = 0;
ts.nlr_jump_callback_top = NULL;
ts.mp_pending_exception = MP_OBJ_NULL;
// set locals and globals from the calling context
mp_locals_set(args->dict_locals);
mp_globals_set(args->dict_globals);
MP_THREAD_GIL_ENTER();
// signal that we are set up and running