refactor: change methods ENTER|EXIT critical

The read and write from BaseType_t, can be do in a atomic context, and
dont need a mutex contol.
Change this methods for access the critical regiao only if is
neccessary. For make this, create a macro in portable.h that apoint to
tasENTER|EXIT_CRITIAL() function. Now, if port is guarantee that access
BaseType_t in atomic context, a empty macro can be define in
portmacro.h, like this:

Signed-off-by: guilherme giacomo simoes <trintaeoitogc@gmail.com>
This commit is contained in:
guilherme giacomo simoes 2024-10-01 23:26:35 -03:00
parent 1cb8042961
commit a118f6a351
4 changed files with 22 additions and 14 deletions

View file

@ -85,6 +85,14 @@
#define portARCH_NAME NULL
#endif
#ifndef portBASE_TYPE_ENTER_CRITICAL
#define portBASE_TYPE_ENTER_CRITICAL() taskENTER_CRITICAL()
#endif
#ifndef portBASE_TYPE_EXIT_CRITICAL
#define portBASE_TYPE_EXIT_CRITICAL() taskEXIT_CRITICAL()
#endif
#ifndef configSTACK_DEPTH_TYPE
#define configSTACK_DEPTH_TYPE StackType_t
#endif

View file

@ -2202,11 +2202,11 @@ UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue )
configASSERT( xQueue );
taskENTER_CRITICAL();
portBASE_TYPE_ENTER_CRITICAL();
{
uxReturn = ( ( Queue_t * ) xQueue )->uxMessagesWaiting;
}
taskEXIT_CRITICAL();
portBASE_TYPE_EXIT_CRITICAL();
traceRETURN_uxQueueMessagesWaiting( uxReturn );
@ -2223,11 +2223,11 @@ UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue )
configASSERT( pxQueue );
taskENTER_CRITICAL();
portBASE_TYPE_ENTER_CRITICAL();
{
uxReturn = ( UBaseType_t ) ( pxQueue->uxLength - pxQueue->uxMessagesWaiting );
}
taskEXIT_CRITICAL();
portBASE_TYPE_EXIT_CRITICAL();
traceRETURN_uxQueueSpacesAvailable( uxReturn );

12
tasks.c
View file

@ -2623,14 +2623,14 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
traceENTER_uxTaskPriorityGet( xTask );
taskENTER_CRITICAL();
portBASE_TYPE_ENTER_CRITICAL();
{
/* If null is passed in here then it is the priority of the task
* that called uxTaskPriorityGet() that is being queried. */
pxTCB = prvGetTCBFromHandle( xTask );
uxReturn = pxTCB->uxPriority;
}
taskEXIT_CRITICAL();
portBASE_TYPE_EXIT_CRITICAL();
traceRETURN_uxTaskPriorityGet( uxReturn );
@ -2697,14 +2697,14 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
traceENTER_uxTaskBasePriorityGet( xTask );
taskENTER_CRITICAL();
portBASE_TYPE_ENTER_CRITICAL();
{
/* If null is passed in here then it is the base priority of the task
* that called uxTaskBasePriorityGet() that is being queried. */
pxTCB = prvGetTCBFromHandle( xTask );
uxReturn = pxTCB->uxBasePriority;
}
taskEXIT_CRITICAL();
portBASE_TYPE_EXIT_CRITICAL();
traceRETURN_uxTaskBasePriorityGet( uxReturn );
@ -3040,12 +3040,12 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
traceENTER_vTaskCoreAffinityGet( xTask );
taskENTER_CRITICAL();
portBASE_TYPE_ENTER_CRITICAL();
{
pxTCB = prvGetTCBFromHandle( xTask );
uxCoreAffinityMask = pxTCB->uxCoreAffinityMask;
}
taskEXIT_CRITICAL();
portBASE_TYPE_EXIT_CRITICAL();
traceRETURN_vTaskCoreAffinityGet( uxCoreAffinityMask );

View file

@ -601,7 +601,7 @@
traceENTER_xTimerGetReloadMode( xTimer );
configASSERT( xTimer );
taskENTER_CRITICAL();
portBASE_TYPE_ENTER_CRITICAL();
{
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0U )
{
@ -614,7 +614,7 @@
xReturn = pdTRUE;
}
}
taskEXIT_CRITICAL();
portBASE_TYPE_EXIT_CRITICAL();
traceRETURN_xTimerGetReloadMode( xReturn );
@ -1169,7 +1169,7 @@
configASSERT( xTimer );
/* Is the timer in the list of active timers? */
taskENTER_CRITICAL();
portBASE_TYPE_ENTER_CRITICAL();
{
if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0U )
{
@ -1180,7 +1180,7 @@
xReturn = pdTRUE;
}
}
taskEXIT_CRITICAL();
portBASE_TYPE_EXIT_CRITICAL();
traceRETURN_xTimerIsTimerActive( xReturn );