mirror of https://github.com/ARMmbed/mbed-os.git
Add Thread::join call for exiting threads without forceful termination
Allows multiple threads to join without forceful termination. Allows threads to synchronize on cleanup.
parent
8b8606b98d
commit
d15cd7826a
|
@ -39,7 +39,7 @@ Thread::Thread(void (*task)(void const *argument), void *argument,
|
|||
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;
|
||||
return osErrorParameter;
|
||||
}
|
||||
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
|
@ -73,6 +73,20 @@ osStatus Thread::terminate() {
|
|||
return osThreadTerminate(_tid);
|
||||
}
|
||||
|
||||
osStatus Thread::join() {
|
||||
while (true) {
|
||||
uint8_t state = get_state();
|
||||
if (state == Thread::Inactive || state == osErrorParameter) {
|
||||
return osOK;
|
||||
}
|
||||
|
||||
osStatus status = yield();
|
||||
if (status != osOK) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
osStatus Thread::set_priority(osPriority priority) {
|
||||
return osThreadSetPriority(_tid, priority);
|
||||
}
|
||||
|
|
|
@ -59,6 +59,11 @@ public:
|
|||
uint32_t stack_size=DEFAULT_STACK_SIZE,
|
||||
unsigned char *stack_pointer=NULL);
|
||||
|
||||
/** Wait for thread to terminate
|
||||
@return status code that indicates the execution status of the function.
|
||||
*/
|
||||
osStatus join();
|
||||
|
||||
/** 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