freertos: prvCheckTasksWaitingTermination bugfix

Bugfix to prevent a self deleting no affinity task's memory from being freed by the
idle task of the other core before the self deleting no affinity task is able to context
switch out.  prvCheckTasksWaitingTermination now checks if the task is still on
pxCurrentTCB before freeing task memory.
This commit is contained in:
Darian Leung
2017-12-18 21:58:15 +08:00
parent 5401a75bad
commit c41c02872f
2 changed files with 26 additions and 4 deletions

View File

@@ -3643,10 +3643,15 @@ static void prvCheckTasksWaitingTermination( void )
/* We only want to kill tasks that ran on this core because e.g. _xt_coproc_release needs to
be called on the core the process is pinned on, if any */
ListItem_t *target = listGET_HEAD_ENTRY(&xTasksWaitingTermination);
for( ; target != listGET_END_MARKER(&xTasksWaitingTermination); target = listGET_NEXT(target) ){
int coreid = (( TCB_t * )listGET_LIST_ITEM_OWNER(target))->xCoreID;
if(coreid == core || coreid == tskNO_AFFINITY){ //Find first item not pinned to other core
pxTCB = ( TCB_t * )listGET_LIST_ITEM_OWNER(target);
for( ; target != listGET_END_MARKER(&xTasksWaitingTermination); target = listGET_NEXT(target) ){ //Walk the list
TCB_t *tgt_tcb = ( TCB_t * )listGET_LIST_ITEM_OWNER(target);
int affinity = tgt_tcb->xCoreID;
//Self deleting tasks are added to Termination List before they switch context. Ensure they aren't still currently running
if( pxCurrentTCB[core] == tgt_tcb || (portNUM_PROCESSORS > 1 && pxCurrentTCB[!core] == tgt_tcb) ){
continue; //Can't free memory of task that is still running
}
if(affinity == core || affinity == tskNO_AFFINITY){ //Find first item not pinned to other core
pxTCB = tgt_tcb;
break;
}
}