Skip to content

Commit f6f78a2

Browse files
committed
Merge branch 'main' into remove-type-taskrunning
2 parents 0e03f1a + 53229b1 commit f6f78a2

File tree

1 file changed

+44
-49
lines changed

1 file changed

+44
-49
lines changed

tasks.c

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -690,62 +690,57 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
690690
UBaseType_t uxPrevCriticalNesting;
691691
const TCB_t * pxThisTCB;
692692

693-
/* This should be skipped if called from an ISR. If the task on the current
694-
* core is no longer running, then vTaskSwitchContext() probably should
695-
* be run before returning, but we don't have a way to force that to happen
696-
* from here. */
697-
if( portCHECK_IF_IN_ISR() == pdFALSE )
698-
{
699-
/* This function is always called with interrupts disabled
700-
* so this is safe. */
701-
pxThisTCB = pxCurrentTCBs[ portGET_CORE_ID() ];
702-
703-
while( pxThisTCB->xTaskRunState == taskTASK_SCHEDULED_TO_YIELD )
704-
{
705-
/* We are only here if we just entered a critical section
706-
* or if we just suspended the scheduler, and another task
707-
* has requested that we yield.
708-
*
709-
* This is slightly complicated since we need to save and restore
710-
* the suspension and critical nesting counts, as well as release
711-
* and reacquire the correct locks. And then, do it all over again
712-
* if our state changed again during the reacquisition. */
713-
uxPrevCriticalNesting = portGET_CRITICAL_NESTING_COUNT();
714-
715-
if( uxPrevCriticalNesting > 0U )
716-
{
717-
portSET_CRITICAL_NESTING_COUNT( 0U );
718-
portRELEASE_ISR_LOCK();
719-
}
720-
else
721-
{
722-
/* The scheduler is suspended. uxSchedulerSuspended is updated
723-
* only when the task is not requested to yield. */
724-
mtCOVERAGE_TEST_MARKER();
725-
}
693+
/* This must only be called from within a task. */
694+
portASSERT_IF_IN_ISR();
695+
696+
/* This function is always called with interrupts disabled
697+
* so this is safe. */
698+
pxThisTCB = pxCurrentTCBs[ portGET_CORE_ID() ];
699+
700+
while( pxThisTCB->xTaskRunState == taskTASK_SCHEDULED_TO_YIELD )
701+
{
702+
/* We are only here if we just entered a critical section
703+
* or if we just suspended the scheduler, and another task
704+
* has requested that we yield.
705+
*
706+
* This is slightly complicated since we need to save and restore
707+
* the suspension and critical nesting counts, as well as release
708+
* and reacquire the correct locks. And then, do it all over again
709+
* if our state changed again during the reacquisition. */
710+
uxPrevCriticalNesting = portGET_CRITICAL_NESTING_COUNT();
726711

727-
portRELEASE_TASK_LOCK();
712+
if( uxPrevCriticalNesting > 0U )
713+
{
714+
portSET_CRITICAL_NESTING_COUNT( 0U );
715+
portRELEASE_ISR_LOCK();
716+
}
717+
else
718+
{
719+
/* The scheduler is suspended. uxSchedulerSuspended is updated
720+
* only when the task is not requested to yield. */
721+
mtCOVERAGE_TEST_MARKER();
722+
}
728723

729-
portMEMORY_BARRIER();
730-
configASSERT( pxThisTCB->xTaskRunState == taskTASK_SCHEDULED_TO_YIELD );
724+
portRELEASE_TASK_LOCK();
725+
portMEMORY_BARRIER();
726+
configASSERT( pxThisTCB->xTaskRunState == taskTASK_SCHEDULED_TO_YIELD );
731727

732-
portENABLE_INTERRUPTS();
728+
portENABLE_INTERRUPTS();
733729

734-
/* Enabling interrupts should cause this core to immediately
735-
* service the pending interrupt and yield. If the run state is still
736-
* yielding here then that is a problem. */
737-
configASSERT( pxThisTCB->xTaskRunState != taskTASK_SCHEDULED_TO_YIELD );
730+
/* Enabling interrupts should cause this core to immediately
731+
* service the pending interrupt and yield. If the run state is still
732+
* yielding here then that is a problem. */
733+
configASSERT( pxThisTCB->xTaskRunState != taskTASK_SCHEDULED_TO_YIELD );
738734

739-
portDISABLE_INTERRUPTS();
740-
portGET_TASK_LOCK();
741-
portGET_ISR_LOCK();
735+
portDISABLE_INTERRUPTS();
736+
portGET_TASK_LOCK();
737+
portGET_ISR_LOCK();
742738

743-
portSET_CRITICAL_NESTING_COUNT( uxPrevCriticalNesting );
739+
portSET_CRITICAL_NESTING_COUNT( uxPrevCriticalNesting );
744740

745-
if( uxPrevCriticalNesting == 0U )
746-
{
747-
portRELEASE_ISR_LOCK();
748-
}
741+
if( uxPrevCriticalNesting == 0U )
742+
{
743+
portRELEASE_ISR_LOCK();
749744
}
750745
}
751746
}

0 commit comments

Comments
 (0)