diff --git a/core/mbed-rtos/rtos/Thread.cpp b/core/mbed-rtos/rtos/Thread.cpp index ed8270a36a..5ebb72d005 100644 --- a/core/mbed-rtos/rtos/Thread.cpp +++ b/core/mbed-rtos/rtos/Thread.cpp @@ -26,8 +26,22 @@ namespace rtos { +Thread::Thread() { + _tid = NULL; +} + 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); +} + +osStatus Thread::start(void (*task)(void const *argument), void *argument, + osPriority priority, uint32_t stack_size, unsigned char *stack_pointer) { + if (_tid != NULL) { + return osErrorResource; + } + #ifdef __MBED_CMSIS_RTOS_CM _thread_def.pthread = task; _thread_def.tpriority = priority; @@ -48,6 +62,11 @@ Thread::Thread(void (*task)(void const *argument), void *argument, } #endif _tid = osThreadCreate(&_thread_def, argument); + if (_tid == NULL) { + return osErrorResource; + } + + return osOK; } osStatus Thread::terminate() { diff --git a/core/mbed-rtos/rtos/Thread.h b/core/mbed-rtos/rtos/Thread.h index 3e787983ab..0da6764a00 100644 --- a/core/mbed-rtos/rtos/Thread.h +++ b/core/mbed-rtos/rtos/Thread.h @@ -30,6 +30,10 @@ namespace rtos { /** The Thread class allow defining, creating, and controlling thread functions in the system. */ class Thread { public: + /** Allocate a new thread without starting execution + */ + Thread(); + /** Create a new thread, and start it 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). @@ -42,6 +46,19 @@ public: uint32_t stack_size=DEFAULT_STACK_SIZE, unsigned char *stack_pointer=NULL); + /** 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); + /** Terminate execution of a thread and remove it from Active Threads @return status code that indicates the execution status of the function. */