diff options
| author | Damien George <damien.p.george@gmail.com> | 2016-05-30 16:56:51 +0100 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2016-06-28 11:28:51 +0100 |
| commit | df95f52583e0f5e3f2a74f7461bb00e2f24b3079 (patch) | |
| tree | bcde53b237e60eeba2b0fd5e1e21e023d3c614fb /cc3200 | |
| parent | eef4f13a3390dc88902563acb047f0439eff0caf (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 'cc3200')
| -rw-r--r-- | cc3200/mpthreadport.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/cc3200/mpthreadport.c b/cc3200/mpthreadport.c index 7cc44d73d..a9fb3f0d4 100644 --- a/cc3200/mpthreadport.c +++ b/cc3200/mpthreadport.c @@ -107,32 +107,37 @@ STATIC void freertos_entry(void *arg) { } } -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) { // store thread entry function into a global variable so we can access it ext_thread_entry = entry; - if (stack_size == 0) { - stack_size = 2048; // default stack size + if (*stack_size == 0) { + *stack_size = 4096; // default stack size + } else if (*stack_size < 2048) { + *stack_size = 2048; // minimum stack size } mp_thread_mutex_lock(&thread_mutex, 1); // create thread - StackType_t *stack = m_new(StackType_t, stack_size / sizeof(StackType_t)); + StackType_t *stack = m_new(StackType_t, *stack_size / sizeof(StackType_t)); StaticTask_t *task_buf = m_new(StaticTask_t, 1); - TaskHandle_t id = xTaskCreateStatic(freertos_entry, "Thread", stack_size / sizeof(void*), arg, 2, stack, task_buf); + TaskHandle_t id = xTaskCreateStatic(freertos_entry, "Thread", *stack_size / sizeof(void*), arg, 2, stack, task_buf); if (id == NULL) { mp_thread_mutex_unlock(&thread_mutex); nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, "can't create thread")); } + // adjust stack_size to provide room to recover from hitting the limit + *stack_size -= 512; + // add thread to linked list of all threads thread_t *th = m_new_obj(thread_t); th->id = id; th->ready = 0; th->arg = arg; th->stack = stack; - th->stack_len = stack_size / sizeof(StackType_t); + th->stack_len = *stack_size / sizeof(StackType_t); th->next = thread; thread = th; |
