aboutsummaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorDamien George2016-05-30 16:56:51 +0100
committerDamien George2016-06-28 11:28:51 +0100
commitdf95f52583e0f5e3f2a74f7461bb00e2f24b3079 (patch)
treebcde53b237e60eeba2b0fd5e1e21e023d3c614fb /py
parenteef4f13a3390dc88902563acb047f0439eff0caf (diff)
py/modthread: Allow to properly set the stack limit of a thread.
We rely on the port setting and adjusting the stack size so there is enough room to recover from hitting the stack limit.
Diffstat (limited to 'py')
-rw-r--r--py/modthread.c8
-rw-r--r--py/mpthread.h2
2 files changed, 7 insertions, 3 deletions
diff --git a/py/modthread.c b/py/modthread.c
index e5d040671..6c8340c92 100644
--- a/py/modthread.c
+++ b/py/modthread.c
@@ -160,6 +160,7 @@ STATIC mp_obj_t mod_thread_stack_size(size_t n_args, const mp_obj_t *args) {
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 {
+ size_t stack_size;
mp_obj_t fun;
size_t n_args;
size_t n_kw;
@@ -175,7 +176,7 @@ STATIC void *thread_entry(void *args_in) {
mp_thread_set_state(&ts);
mp_stack_set_top(&ts + 1); // need to include ts in root-pointer scan
- mp_stack_set_limit(16 * 1024); // fixed stack limit for now
+ mp_stack_set_limit(args->stack_size);
MP_THREAD_GIL_ENTER();
@@ -256,11 +257,14 @@ STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args)
th_args->n_args = pos_args_len;
memcpy(th_args->args, pos_args_items, pos_args_len * sizeof(mp_obj_t));
+ // set the stack size to use
+ th_args->stack_size = thread_stack_size;
+
// set the function for thread entry
th_args->fun = args[0];
// spawn the thread!
- mp_thread_create(thread_entry, th_args, thread_stack_size);
+ mp_thread_create(thread_entry, th_args, &th_args->stack_size);
return mp_const_none;
}
diff --git a/py/mpthread.h b/py/mpthread.h
index 75e8984ba..7f8d4dec7 100644
--- a/py/mpthread.h
+++ b/py/mpthread.h
@@ -40,7 +40,7 @@ struct _mp_state_thread_t;
struct _mp_state_thread_t *mp_thread_get_state(void);
void mp_thread_set_state(void *state);
-void mp_thread_create(void *(*entry)(void*), void *arg, size_t stack_size);
+void mp_thread_create(void *(*entry)(void*), void *arg, size_t *stack_size);
void mp_thread_start(void);
void mp_thread_finish(void);
void mp_thread_mutex_init(mp_thread_mutex_t *mutex);