File tree Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ namespace rtos {
44
44
void Thread::constructor (osPriority priority,
45
45
uint32_t stack_size, unsigned char *stack_pointer) {
46
46
_tid = 0 ;
47
+ _finished = false ;
47
48
_dynamic_stack = (stack_pointer == NULL );
48
49
49
50
#if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM)
@@ -74,7 +75,7 @@ void Thread::constructor(Callback<void()> task,
74
75
osStatus Thread::start (Callback<void ()> task) {
75
76
_mutex.lock ();
76
77
77
- if (_tid != 0 ) {
78
+ if (( _tid != 0 ) || _finished ) {
78
79
_mutex.unlock ();
79
80
return osErrorParameter;
80
81
}
@@ -117,6 +118,7 @@ osStatus Thread::terminate() {
117
118
osThreadId local_id = _tid;
118
119
_join_sem.release ();
119
120
_tid = (osThreadId)NULL ;
121
+ _finished = true ;
120
122
121
123
ret = osThreadTerminate (local_id);
122
124
@@ -367,6 +369,7 @@ void Thread::_thunk(const void * thread_ptr)
367
369
t->_task ();
368
370
t->_mutex .lock ();
369
371
t->_tid = (osThreadId)NULL ;
372
+ t->_finished = true ;
370
373
t->_join_sem .release ();
371
374
// rtos will release the mutex automatically
372
375
}
Original file line number Diff line number Diff line change @@ -197,6 +197,7 @@ class Thread {
197
197
/* * Starts a thread executing the specified function.
198
198
@param task function to be executed by this thread.
199
199
@return status code that indicates the execution status of the function.
200
+ @note a thread can only be started once
200
201
*/
201
202
osStatus start (mbed::Callback<void ()> task);
202
203
@@ -344,9 +345,10 @@ class Thread {
344
345
mbed::Callback<void ()> _task;
345
346
osThreadId _tid;
346
347
osThreadDef_t _thread_def;
347
- bool _dynamic_stack;
348
348
Semaphore _join_sem;
349
349
Mutex _mutex;
350
+ bool _dynamic_stack;
351
+ bool _finished;
350
352
};
351
353
352
354
}
You can’t perform that action at this time.
0 commit comments