kopia lustrzana https://github.com/micropython/micropython
py/modthread: Move thread state initialisation to shared function.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>pull/13774/head
rodzic
678707c8b0
commit
bc424ddc41
|
@ -34,7 +34,6 @@
|
||||||
#include "py/objarray.h"
|
#include "py/objarray.h"
|
||||||
#include "py/qstr.h"
|
#include "py/qstr.h"
|
||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "py/stackctrl.h"
|
|
||||||
#include "extmod/modbluetooth.h"
|
#include "extmod/modbluetooth.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -1272,14 +1271,7 @@ STATIC mp_obj_t invoke_irq_handler(uint16_t event,
|
||||||
|
|
||||||
mp_state_thread_t ts;
|
mp_state_thread_t ts;
|
||||||
if (ts_orig == NULL) {
|
if (ts_orig == NULL) {
|
||||||
mp_thread_set_state(&ts);
|
mp_thread_init_state(&ts, MICROPY_PY_BLUETOOTH_SYNC_EVENT_STACK_SIZE, NULL, NULL);
|
||||||
mp_stack_set_top(&ts + 1); // need to include ts in root-pointer scan
|
|
||||||
mp_stack_set_limit(MICROPY_PY_BLUETOOTH_SYNC_EVENT_STACK_SIZE);
|
|
||||||
ts.gc_lock_depth = 0;
|
|
||||||
ts.nlr_jump_callback_top = NULL;
|
|
||||||
ts.mp_pending_exception = MP_OBJ_NULL;
|
|
||||||
mp_locals_set(mp_state_ctx.thread.dict_locals); // set from the outer context
|
|
||||||
mp_globals_set(mp_state_ctx.thread.dict_globals); // set from the outer context
|
|
||||||
MP_THREAD_GIL_ENTER();
|
MP_THREAD_GIL_ENTER();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -160,10 +160,7 @@ STATIC void *thread_entry(void *args_in) {
|
||||||
thread_entry_args_t *args = (thread_entry_args_t *)args_in;
|
thread_entry_args_t *args = (thread_entry_args_t *)args_in;
|
||||||
|
|
||||||
mp_state_thread_t ts;
|
mp_state_thread_t ts;
|
||||||
mp_thread_set_state(&ts);
|
mp_thread_init_state(&ts, args->stack_size, args->dict_locals, args->dict_globals);
|
||||||
|
|
||||||
mp_stack_set_top(&ts + 1); // need to include ts in root-pointer scan
|
|
||||||
mp_stack_set_limit(args->stack_size);
|
|
||||||
|
|
||||||
#if MICROPY_ENABLE_PYSTACK
|
#if MICROPY_ENABLE_PYSTACK
|
||||||
// TODO threading and pystack is not fully supported, for now just make a small stack
|
// 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]);
|
mp_pystack_init(mini_pystack, &mini_pystack[128]);
|
||||||
#endif
|
#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();
|
MP_THREAD_GIL_ENTER();
|
||||||
|
|
||||||
// signal that we are set up and running
|
// signal that we are set up and running
|
||||||
|
|
27
py/runtime.h
27
py/runtime.h
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include "py/mpstate.h"
|
#include "py/mpstate.h"
|
||||||
#include "py/pystack.h"
|
#include "py/pystack.h"
|
||||||
|
#include "py/stackctrl.h"
|
||||||
|
|
||||||
// For use with mp_call_function_1_from_nlr_jump_callback.
|
// For use with mp_call_function_1_from_nlr_jump_callback.
|
||||||
#define MP_DEFINE_NLR_JUMP_CALLBACK_FUNCTION_1(ctx, f, a) \
|
#define MP_DEFINE_NLR_JUMP_CALLBACK_FUNCTION_1(ctx, f, a) \
|
||||||
|
@ -154,6 +155,32 @@ static inline void mp_globals_set(mp_obj_dict_t *d) {
|
||||||
void mp_globals_locals_set_from_nlr_jump_callback(void *ctx_in);
|
void mp_globals_locals_set_from_nlr_jump_callback(void *ctx_in);
|
||||||
void mp_call_function_1_from_nlr_jump_callback(void *ctx_in);
|
void mp_call_function_1_from_nlr_jump_callback(void *ctx_in);
|
||||||
|
|
||||||
|
#if MICROPY_PY_THREAD
|
||||||
|
static inline void mp_thread_init_state(mp_state_thread_t *ts, size_t stack_size, mp_obj_dict_t *locals, mp_obj_dict_t *globals) {
|
||||||
|
mp_thread_set_state(ts);
|
||||||
|
|
||||||
|
mp_stack_set_top(ts + 1); // need to include ts in root-pointer scan
|
||||||
|
mp_stack_set_limit(stack_size);
|
||||||
|
|
||||||
|
// GC starts off unlocked
|
||||||
|
ts->gc_lock_depth = 0;
|
||||||
|
|
||||||
|
// There are no pending jump callbacks or exceptions yet
|
||||||
|
ts->nlr_jump_callback_top = NULL;
|
||||||
|
ts->mp_pending_exception = MP_OBJ_NULL;
|
||||||
|
|
||||||
|
// If locals/globals are not given, inherit from main thread
|
||||||
|
if (locals == NULL) {
|
||||||
|
locals = mp_state_ctx.thread.dict_locals;
|
||||||
|
}
|
||||||
|
if (globals == NULL) {
|
||||||
|
globals = mp_state_ctx.thread.dict_globals;
|
||||||
|
}
|
||||||
|
mp_locals_set(locals);
|
||||||
|
mp_globals_set(globals);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
mp_obj_t mp_load_name(qstr qst);
|
mp_obj_t mp_load_name(qstr qst);
|
||||||
mp_obj_t mp_load_global(qstr qst);
|
mp_obj_t mp_load_global(qstr qst);
|
||||||
mp_obj_t mp_load_build_class(void);
|
mp_obj_t mp_load_build_class(void);
|
||||||
|
|
Ładowanie…
Reference in New Issue