mirror of https://github.com/ARMmbed/mbed-os.git
Add start function for separating object allocation from thread initialization
Allows threads to started separately from when they are declared, avoiding the need to dynamically allocate threads at runtime.
parent
1ae994fb62
commit
8b8606b98d
|
@ -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() {
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue