diff options
author | David Lechner <david@pybricks.com> | 2020-01-09 16:35:13 -0600 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-01-12 13:27:04 +1100 |
commit | 339d0816c55a0c62ec9be810dd3a58d36b952510 (patch) | |
tree | 625f950e32d0eb420fd78d43a35ccc166eb4103b /py/runtime.c | |
parent | 853aaa06f24c98191a44a38eedd4ec2a0e63d3eb (diff) |
py/runtime: Move MICROPY_PORT_INIT_FUNC near the end of mp_init().
This moves the MICROPY_PORT_INIT_FUNC hook to the end of mp_init(), just
before MP_THREAD_GIL_ENTER(), so that everything (in particular the GIL
mutex) is intialized before the hook is called. MICROPY_PORT_DEINIT_FUNC
is also moved to be symmetric (but there is no functional change there).
If a port needs to perform initialisation earlier than
MICROPY_PORT_INIT_FUNC then it can do it before calling mp_init().
Diffstat (limited to 'py/runtime.c')
-rw-r--r-- | py/runtime.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/py/runtime.c b/py/runtime.c index 26b473bbe..db044cf7c 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -81,11 +81,6 @@ void mp_init(void) { MP_STATE_VM(mp_kbd_exception).args = (mp_obj_tuple_t*)&mp_const_empty_tuple_obj; #endif - // call port specific initialization if any -#ifdef MICROPY_PORT_INIT_FUNC - MICROPY_PORT_INIT_FUNC; -#endif - #if MICROPY_ENABLE_COMPILER // optimization disabled by default MP_STATE_VM(mp_optimise_value) = 0; @@ -140,19 +135,24 @@ void mp_init(void) { mp_thread_mutex_init(&MP_STATE_VM(gil_mutex)); #endif + // call port specific initialization if any + #ifdef MICROPY_PORT_INIT_FUNC + MICROPY_PORT_INIT_FUNC; + #endif + MP_THREAD_GIL_ENTER(); } void mp_deinit(void) { MP_THREAD_GIL_EXIT(); - //mp_obj_dict_free(&dict_main); - //mp_map_deinit(&MP_STATE_VM(mp_loaded_modules_map)); - // call port specific deinitialization if any -#ifdef MICROPY_PORT_DEINIT_FUNC + #ifdef MICROPY_PORT_DEINIT_FUNC MICROPY_PORT_DEINIT_FUNC; -#endif + #endif + + //mp_obj_dict_free(&dict_main); + //mp_map_deinit(&MP_STATE_VM(mp_loaded_modules_map)); } mp_obj_t mp_load_name(qstr qst) { |