Skip to content

Commit 4d7b2f6

Browse files
committed
Pend a yield in portPRE_TASK_DELETE_HOOK
When a task deletes itself, it calls portPRE_TASK_DELETE_HOOK which translates to vPortCloseRunningThread on the Windows port. vPortCloseRunningThread never returns and as a result, taskYIELD_WITHIN_API in vTaskDelete does not get called. As a result, the next task is not scheduled when configUSE_PREEMPTION is set to 0. This change records that a yield is pending so that the next tick interrupt switches out the task that was deleted. Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
1 parent e6d8308 commit 4d7b2f6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

portable/MSVC-MingW/port.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,20 @@ void vPortCloseRunningThread( void * pvTaskToDelete,
547547
/* This is called from a critical section, which must be exited before the
548548
* thread stops. */
549549
taskEXIT_CRITICAL();
550+
551+
/* Record that a yield is pending so that the next tick interrupt switches
552+
* out this thread regardless of the value of configUSE_PREEMPTION. This is
553+
* needed when a task deletes itself - the taskYIELD_WITHIN_API within
554+
* vTaskDelete does not get called because this function never returns. If
555+
* we do not pend portINTERRUPT_YIELD here, the next task is not scheduled
556+
* when configUSE_PREEMPTION is set to 0. */
557+
if( pvInterruptEventMutex != NULL )
558+
{
559+
WaitForSingleObject( pvInterruptEventMutex, INFINITE );
560+
ulPendingInterrupts |= ( 1 << portINTERRUPT_YIELD );
561+
ReleaseMutex( pvInterruptEventMutex );
562+
}
563+
550564
CloseHandle( pxThreadState->pvYieldEvent );
551565
ExitThread( 0 );
552566
}

0 commit comments

Comments
 (0)