Posix: Fix no task switching issue if a task ended

When the main function of a task exits, no task switching happened.
This is because all the remaining tasks are waiting on the condition
variable. The fix is to trigger a task switch and mark the exiting
task as "Dying" to be suspened and exited properly from the scheduler.
This commit is contained in:
Reda Maher 2020-09-29 10:16:14 +02:00 committed by Reda Maher
parent d428209d01
commit a4e007e755

View file

@ -66,6 +66,7 @@
/*-----------------------------------------------------------*/
#define SIG_RESUME SIGUSR1
#define portTASK_ENDED_DELAY ( 500 )
typedef struct THREAD
{
@ -421,6 +422,14 @@ Thread_t *pxThread = pvParams;
/* Call the task's entry point. */
pxThread->pxCode( pxThread->pvParams );
/* The task has finished, we need to trigger a task switch here
* to avoid exiting while all tasks are waiting to be signaled.
* So we will mark the task as Dying here then delay the task
* with any value to trigger a task switch where the task will
* be suspended and exited. */
pxThread->xDying = pdTRUE;
vTaskDelay( portTASK_ENDED_DELAY );
return NULL;
}
/*-----------------------------------------------------------*/