@@ -32,9 +32,11 @@ extern "C" P_TCB rt_tid2ptcb(osThreadId thread_id);
3232
3333namespace rtos {
3434
35- Thread::Thread (osPriority priority,
36- uint32_t stack_size, unsigned char *stack_pointer):
37- _tid (0 ), _dynamic_stack(stack_pointer == NULL ) {
35+ void Thread::constructor (osPriority priority,
36+ uint32_t stack_size, unsigned char *stack_pointer) {
37+ _tid = 0 ;
38+ _dynamic_stack = (stack_pointer == NULL );
39+
3840#if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM)
3941 _thread_def.tpriority = priority;
4042 _thread_def.stacksize = stack_size;
@@ -44,16 +46,9 @@ Thread::Thread(osPriority priority,
4446
4547void Thread::constructor (Callback<void ()> task,
4648 osPriority priority, uint32_t stack_size, unsigned char *stack_pointer) {
47- _tid = 0 ;
48- _dynamic_stack = (stack_pointer == NULL );
49+ constructor (priority, stack_size, stack_pointer);
4950
50- _task = task;
51- #if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM)
52- _thread_def.tpriority = priority;
53- _thread_def.stacksize = stack_size;
54- _thread_def.stack_pointer = (uint32_t *)stack_pointer;
55- #endif
56- switch (start ((void (*)(const void *))Callback<void ()>::thunk, &_task)) {
51+ switch (start (task)) {
5752 case osErrorResource:
5853 error (" OS ran out of threads!\n " );
5954 break ;
@@ -67,13 +62,13 @@ void Thread::constructor(Callback<void()> task,
6762 }
6863}
6964
70- osStatus Thread::start (void (*task)( void const *argument), void *argument ) {
71- if (_tid != NULL ) {
65+ osStatus Thread::start (Callback< void ()> task ) {
66+ if (_tid != 0 ) {
7267 return osErrorParameter;
7368 }
7469
7570#if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM)
76- _thread_def.pthread = task ;
71+ _thread_def.pthread = ( void (*)( const void *))Callback< void ()>::thunk ;
7772 if (_thread_def.stack_pointer == NULL ) {
7873 _thread_def.stack_pointer = new uint32_t [_thread_def.stacksize /sizeof (uint32_t )];
7974 if (_thread_def.stack_pointer == NULL )
@@ -85,6 +80,7 @@ osStatus Thread::start(void (*task)(void const *argument), void *argument) {
8580 _thread_def.stack_pointer [i] = 0xE25A2EA5 ;
8681 }
8782#endif
83+ _task = task;
8884 _tid = osThreadCreate (&_thread_def, &_task);
8985 if (_tid == NULL ) {
9086 if (_dynamic_stack) delete[] (_thread_def.stack_pointer );
0 commit comments