From 21e68f3c9116c4fa4e62bfb9eb88247845a70fc7 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sat, 23 Apr 2016 03:40:05 -0500 Subject: [PATCH] Move configuration arguments to only constructor --- core/mbed-rtos/rtos/Thread.cpp | 30 +++++++++++++++++------------- core/mbed-rtos/rtos/Thread.h | 20 +++++++++++--------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/core/mbed-rtos/rtos/Thread.cpp b/core/mbed-rtos/rtos/Thread.cpp index 82ce688119..70ffa9e30c 100644 --- a/core/mbed-rtos/rtos/Thread.cpp +++ b/core/mbed-rtos/rtos/Thread.cpp @@ -26,38 +26,42 @@ namespace rtos { -Thread::Thread() { +Thread::Thread(osPriority priority, + uint32_t stack_size, unsigned char *stack_pointer) { _tid = NULL; + _priority = priority; + _stack_size = stack_size; + _stack_pointer = stack_pointer; } Thread::Thread(void (*task)(void const *argument), void *argument, osPriority priority, uint32_t stack_size, unsigned char *stack_pointer) { _tid = NULL; - start(task, argument, priority, stack_size, stack_pointer); + _priority = priority; + _stack_size = stack_size; + _stack_pointer = stack_pointer; + start(task, argument); } -osStatus Thread::start(void (*task)(void const *argument), void *argument, - osPriority priority, uint32_t stack_size, unsigned char *stack_pointer) { +osStatus Thread::start(void (*task)(void const *argument), void *argument) { if (_tid != NULL) { return osErrorParameter; } #ifdef __MBED_CMSIS_RTOS_CM _thread_def.pthread = task; - _thread_def.tpriority = priority; - _thread_def.stacksize = stack_size; - if (stack_pointer != NULL) { - _thread_def.stack_pointer = (uint32_t*)stack_pointer; - _dynamic_stack = false; + _thread_def.tpriority = _priority; + _thread_def.stacksize = _stack_size; + if (_stack_pointer != NULL) { + _thread_def.stack_pointer = (uint32_t*)_stack_pointer; } else { - _thread_def.stack_pointer = new uint32_t[stack_size/sizeof(uint32_t)]; + _thread_def.stack_pointer = new uint32_t[_stack_size/sizeof(uint32_t)]; if (_thread_def.stack_pointer == NULL) error("Error allocating the stack memory\n"); - _dynamic_stack = true; } //Fill the stack with a magic word for maximum usage checking - for (uint32_t i = 0; i < (stack_size / sizeof(uint32_t)); i++) { + for (uint32_t i = 0; i < (_stack_size / sizeof(uint32_t)); i++) { _thread_def.stack_pointer[i] = 0xE25A2EA5; } #endif @@ -191,7 +195,7 @@ void Thread::attach_idle_hook(void (*fptr)(void)) { Thread::~Thread() { terminate(); #ifdef __MBED_CMSIS_RTOS_CM - if (_dynamic_stack) { + if (_stack_pointer == NULL) { delete[] (_thread_def.stack_pointer); } #endif diff --git a/core/mbed-rtos/rtos/Thread.h b/core/mbed-rtos/rtos/Thread.h index c172f88930..1cbc93afa4 100644 --- a/core/mbed-rtos/rtos/Thread.h +++ b/core/mbed-rtos/rtos/Thread.h @@ -31,8 +31,13 @@ namespace rtos { class Thread { public: /** Allocate a new thread without starting execution + @param priority initial priority of the thread function. (default: osPriorityNormal). + @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE). + @param stack_pointer pointer to the stack area to be used by this thread (default: NULL). */ - Thread(); + Thread(osPriority priority=osPriorityNormal, + uint32_t stack_size=DEFAULT_STACK_SIZE, + unsigned char *stack_pointer=NULL); /** Create a new thread, and start it executing the specified function. @param task function to be executed by this thread. @@ -49,15 +54,9 @@ public: /** Starts a thread executing the specified function. @param task function to be executed by this thread. @param argument pointer that is passed to the thread function as start argument. (default: NULL). - @param priority initial priority of the thread function. (default: osPriorityNormal). - @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE). - @param stack_pointer pointer to the stack area to be used by this thread (default: NULL). @return status code that indicates the execution status of the function. */ - osStatus start(void (*task)(void const *argument), void *argument=NULL, - osPriority priority=osPriorityNormal, - uint32_t stack_size=DEFAULT_STACK_SIZE, - unsigned char *stack_pointer=NULL); + osStatus start(void (*task)(void const *argument), void *argument=NULL); /** Wait for thread to terminate @return status code that indicates the execution status of the function. @@ -164,7 +163,10 @@ public: private: osThreadId _tid; osThreadDef_t _thread_def; - bool _dynamic_stack; + + osPriority _priority; + uint32_t _stack_size; + unsigned char *_stack_pointer; }; }