diff options
author | Damien George <damien.p.george@gmail.com> | 2016-04-25 09:02:47 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-06-28 11:28:48 +0100 |
commit | 707f98f207d85b1de9814e90254d52a78ac19739 (patch) | |
tree | c1f4546ff29c5117c7a13aa3caf18e604c76e21d /py/modthread.c | |
parent | 3eb7a268091ef68248d58ddb3ad11465f1cb2199 (diff) |
py/modthread: Add stack_size() function.
Diffstat (limited to 'py/modthread.c')
-rw-r--r-- | py/modthread.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/py/modthread.c b/py/modthread.c index 5d01fe601..8135a5e88 100644 --- a/py/modthread.c +++ b/py/modthread.c @@ -45,11 +45,24 @@ /****************************************************************/ // _thread module +STATIC size_t thread_stack_size = 0; + STATIC mp_obj_t mod_thread_get_ident(void) { return mp_obj_new_int_from_uint((uintptr_t)mp_thread_get_state()); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_get_ident_obj, mod_thread_get_ident); +STATIC mp_obj_t mod_thread_stack_size(size_t n_args, const mp_obj_t *args) { + mp_obj_t ret = mp_obj_new_int_from_uint(thread_stack_size); + if (n_args == 0) { + thread_stack_size = 0; + } else { + thread_stack_size = mp_obj_get_int(args[0]); + } + return ret; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_stack_size_obj, 0, 1, mod_thread_stack_size); + typedef struct _thread_entry_args_t { mp_obj_t fun; size_t n_args; @@ -126,8 +139,7 @@ STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args) } th_args->args = all_args; } - // TODO implement setting thread stack size - mp_thread_create(thread_entry, th_args); + mp_thread_create(thread_entry, th_args, thread_stack_size); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_start_new_thread_obj, 2, 3, mod_thread_start_new_thread); @@ -135,6 +147,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_start_new_thread_obj, 2, 3 STATIC const mp_rom_map_elem_t mp_module_thread_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__thread) }, { MP_ROM_QSTR(MP_QSTR_get_ident), MP_ROM_PTR(&mod_thread_get_ident_obj) }, + { MP_ROM_QSTR(MP_QSTR_stack_size), MP_ROM_PTR(&mod_thread_stack_size_obj) }, { MP_ROM_QSTR(MP_QSTR_start_new_thread), MP_ROM_PTR(&mod_thread_start_new_thread_obj) }, }; |