refactor(freertos/smp): Move critical sections inside xTaskPriorityInherit()

xTaskPriorityInherit() is called inside a critical section from queue.c. This
commit moves the critical section into xTaskPriorityInherit().

Co-authored-by: Sudeep Mohanty <sudeep.mohanty@espressif.com>
This commit is contained in:
Darian Leung 2024-06-16 00:31:09 +08:00 committed by Sudeep Mohanty
parent 0030d609a4
commit a6d6d1220f
2 changed files with 67 additions and 67 deletions

View file

@ -1793,11 +1793,7 @@ BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
{ {
if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
{ {
taskENTER_CRITICAL(); xInheritanceOccurred = xTaskPriorityInherit( pxQueue->u.xSemaphore.xMutexHolder );
{
xInheritanceOccurred = xTaskPriorityInherit( pxQueue->u.xSemaphore.xMutexHolder );
}
taskEXIT_CRITICAL();
} }
else else
{ {

128
tasks.c
View file

@ -6643,91 +6643,95 @@ static void prvResetNextTaskUnblockTime( void )
traceENTER_xTaskPriorityInherit( pxMutexHolder ); traceENTER_xTaskPriorityInherit( pxMutexHolder );
/* If the mutex is taken by an interrupt, the mutex holder is NULL. Priority taskENTER_CRITICAL();
* inheritance is not applied in this scenario. */
if( pxMutexHolder != NULL )
{ {
/* If the holder of the mutex has a priority below the priority of /* If the mutex is taken by an interrupt, the mutex holder is NULL. Priority
* the task attempting to obtain the mutex then it will temporarily * inheritance is not applied in this scenario. */
* inherit the priority of the task attempting to obtain the mutex. */ if( pxMutexHolder != NULL )
if( pxMutexHolderTCB->uxPriority < pxCurrentTCB->uxPriority )
{ {
/* Adjust the mutex holder state to account for its new /* If the holder of the mutex has a priority below the priority of
* priority. Only reset the event list item value if the value is * the task attempting to obtain the mutex then it will temporarily
* not being used for anything else. */ * inherit the priority of the task attempting to obtain the mutex. */
if( ( listGET_LIST_ITEM_VALUE( &( pxMutexHolderTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == ( ( TickType_t ) 0U ) ) if( pxMutexHolderTCB->uxPriority < pxCurrentTCB->uxPriority )
{ {
listSET_LIST_ITEM_VALUE( &( pxMutexHolderTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxCurrentTCB->uxPriority ); /* Adjust the mutex holder state to account for its new
} * priority. Only reset the event list item value if the value is
else * not being used for anything else. */
{ if( ( listGET_LIST_ITEM_VALUE( &( pxMutexHolderTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == ( ( TickType_t ) 0U ) )
mtCOVERAGE_TEST_MARKER();
}
/* If the task being modified is in the ready state it will need
* to be moved into a new list. */
if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxMutexHolderTCB->uxPriority ] ), &( pxMutexHolderTCB->xStateListItem ) ) != pdFALSE )
{
if( uxListRemove( &( pxMutexHolderTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )
{ {
/* It is known that the task is in its ready list so listSET_LIST_ITEM_VALUE( &( pxMutexHolderTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxCurrentTCB->uxPriority );
* there is no need to check again and the port level
* reset macro can be called directly. */
portRESET_READY_PRIORITY( pxMutexHolderTCB->uxPriority, uxTopReadyPriority );
} }
else else
{ {
mtCOVERAGE_TEST_MARKER(); mtCOVERAGE_TEST_MARKER();
} }
/* Inherit the priority before being moved into the new list. */ /* If the task being modified is in the ready state it will need
pxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority; * to be moved into a new list. */
prvAddTaskToReadyList( pxMutexHolderTCB ); if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxMutexHolderTCB->uxPriority ] ), &( pxMutexHolderTCB->xStateListItem ) ) != pdFALSE )
#if ( configNUMBER_OF_CORES > 1 )
{ {
/* The priority of the task is raised. Yield for this task if( uxListRemove( &( pxMutexHolderTCB->xStateListItem ) ) == ( UBaseType_t ) 0 )
* if it is not running. */
if( taskTASK_IS_RUNNING( pxMutexHolderTCB ) != pdTRUE )
{ {
prvYieldForTask( pxMutexHolderTCB ); /* It is known that the task is in its ready list so
* there is no need to check again and the port level
* reset macro can be called directly. */
portRESET_READY_PRIORITY( pxMutexHolderTCB->uxPriority, uxTopReadyPriority );
} }
else
{
mtCOVERAGE_TEST_MARKER();
}
/* Inherit the priority before being moved into the new list. */
pxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority;
prvAddTaskToReadyList( pxMutexHolderTCB );
#if ( configNUMBER_OF_CORES > 1 )
{
/* The priority of the task is raised. Yield for this task
* if it is not running. */
if( taskTASK_IS_RUNNING( pxMutexHolderTCB ) != pdTRUE )
{
prvYieldForTask( pxMutexHolderTCB );
}
}
#endif /* if ( configNUMBER_OF_CORES > 1 ) */
}
else
{
/* Just inherit the priority. */
pxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority;
} }
#endif /* if ( configNUMBER_OF_CORES > 1 ) */
}
else
{
/* Just inherit the priority. */
pxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority;
}
traceTASK_PRIORITY_INHERIT( pxMutexHolderTCB, pxCurrentTCB->uxPriority ); traceTASK_PRIORITY_INHERIT( pxMutexHolderTCB, pxCurrentTCB->uxPriority );
/* Inheritance occurred. */ /* Inheritance occurred. */
xReturn = pdTRUE;
}
else
{
if( pxMutexHolderTCB->uxBasePriority < pxCurrentTCB->uxPriority )
{
/* The base priority of the mutex holder is lower than the
* priority of the task attempting to take the mutex, but the
* current priority of the mutex holder is not lower than the
* priority of the task attempting to take the mutex.
* Therefore the mutex holder must have already inherited a
* priority, but inheritance would have occurred if that had
* not been the case. */
xReturn = pdTRUE; xReturn = pdTRUE;
} }
else else
{ {
mtCOVERAGE_TEST_MARKER(); if( pxMutexHolderTCB->uxBasePriority < pxCurrentTCB->uxPriority )
{
/* The base priority of the mutex holder is lower than the
* priority of the task attempting to take the mutex, but the
* current priority of the mutex holder is not lower than the
* priority of the task attempting to take the mutex.
* Therefore the mutex holder must have already inherited a
* priority, but inheritance would have occurred if that had
* not been the case. */
xReturn = pdTRUE;
}
else
{
mtCOVERAGE_TEST_MARKER();
}
} }
} }
else
{
mtCOVERAGE_TEST_MARKER();
}
} }
else taskEXIT_CRITICAL();
{
mtCOVERAGE_TEST_MARKER();
}
traceRETURN_xTaskPriorityInherit( xReturn ); traceRETURN_xTaskPriorityInherit( xReturn );