|
45 | 45 | /****************************************************************/ |
46 | 46 | // _thread module |
47 | 47 |
|
| 48 | +STATIC size_t thread_stack_size = 0; |
| 49 | + |
48 | 50 | STATIC mp_obj_t mod_thread_get_ident(void) { |
49 | 51 | return mp_obj_new_int_from_uint((uintptr_t)mp_thread_get_state()); |
50 | 52 | } |
51 | 53 | STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_get_ident_obj, mod_thread_get_ident); |
52 | 54 |
|
| 55 | +STATIC mp_obj_t mod_thread_stack_size(size_t n_args, const mp_obj_t *args) { |
| 56 | + mp_obj_t ret = mp_obj_new_int_from_uint(thread_stack_size); |
| 57 | + if (n_args == 0) { |
| 58 | + thread_stack_size = 0; |
| 59 | + } else { |
| 60 | + thread_stack_size = mp_obj_get_int(args[0]); |
| 61 | + } |
| 62 | + return ret; |
| 63 | +} |
| 64 | +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_stack_size_obj, 0, 1, mod_thread_stack_size); |
| 65 | + |
53 | 66 | typedef struct _thread_entry_args_t { |
54 | 67 | mp_obj_t fun; |
55 | 68 | size_t n_args; |
@@ -126,15 +139,15 @@ STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args) |
126 | 139 | } |
127 | 140 | th_args->args = all_args; |
128 | 141 | } |
129 | | - // TODO implement setting thread stack size |
130 | | - mp_thread_create(thread_entry, th_args); |
| 142 | + mp_thread_create(thread_entry, th_args, thread_stack_size); |
131 | 143 | return mp_const_none; |
132 | 144 | } |
133 | 145 | STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_start_new_thread_obj, 2, 3, mod_thread_start_new_thread); |
134 | 146 |
|
135 | 147 | STATIC const mp_rom_map_elem_t mp_module_thread_globals_table[] = { |
136 | 148 | { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__thread) }, |
137 | 149 | { MP_ROM_QSTR(MP_QSTR_get_ident), MP_ROM_PTR(&mod_thread_get_ident_obj) }, |
| 150 | + { MP_ROM_QSTR(MP_QSTR_stack_size), MP_ROM_PTR(&mod_thread_stack_size_obj) }, |
138 | 151 | { MP_ROM_QSTR(MP_QSTR_start_new_thread), MP_ROM_PTR(&mod_thread_start_new_thread_obj) }, |
139 | 152 | }; |
140 | 153 |
|
|
0 commit comments