Skip to content

Commit a118f6a

Browse files
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>
1 parent 1cb8042 commit a118f6a

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

include/portable.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@
8585
#define portARCH_NAME NULL
8686
#endif
8787

88+
#ifndef portBASE_TYPE_ENTER_CRITICAL
89+
#define portBASE_TYPE_ENTER_CRITICAL() taskENTER_CRITICAL()
90+
#endif
91+
92+
#ifndef portBASE_TYPE_EXIT_CRITICAL
93+
#define portBASE_TYPE_EXIT_CRITICAL() taskEXIT_CRITICAL()
94+
#endif
95+
8896
#ifndef configSTACK_DEPTH_TYPE
8997
#define configSTACK_DEPTH_TYPE StackType_t
9098
#endif

queue.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,11 +2202,11 @@ UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue )
22022202

22032203
configASSERT( xQueue );
22042204

2205-
taskENTER_CRITICAL();
2205+
portBASE_TYPE_ENTER_CRITICAL();
22062206
{
22072207
uxReturn = ( ( Queue_t * ) xQueue )->uxMessagesWaiting;
22082208
}
2209-
taskEXIT_CRITICAL();
2209+
portBASE_TYPE_EXIT_CRITICAL();
22102210

22112211
traceRETURN_uxQueueMessagesWaiting( uxReturn );
22122212

@@ -2223,11 +2223,11 @@ UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue )
22232223

22242224
configASSERT( pxQueue );
22252225

2226-
taskENTER_CRITICAL();
2226+
portBASE_TYPE_ENTER_CRITICAL();
22272227
{
22282228
uxReturn = ( UBaseType_t ) ( pxQueue->uxLength - pxQueue->uxMessagesWaiting );
22292229
}
2230-
taskEXIT_CRITICAL();
2230+
portBASE_TYPE_EXIT_CRITICAL();
22312231

22322232
traceRETURN_uxQueueSpacesAvailable( uxReturn );
22332233

tasks.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,14 +2623,14 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
26232623

26242624
traceENTER_uxTaskPriorityGet( xTask );
26252625

2626-
taskENTER_CRITICAL();
2626+
portBASE_TYPE_ENTER_CRITICAL();
26272627
{
26282628
/* If null is passed in here then it is the priority of the task
26292629
* that called uxTaskPriorityGet() that is being queried. */
26302630
pxTCB = prvGetTCBFromHandle( xTask );
26312631
uxReturn = pxTCB->uxPriority;
26322632
}
2633-
taskEXIT_CRITICAL();
2633+
portBASE_TYPE_EXIT_CRITICAL();
26342634

26352635
traceRETURN_uxTaskPriorityGet( uxReturn );
26362636

@@ -2697,14 +2697,14 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
26972697

26982698
traceENTER_uxTaskBasePriorityGet( xTask );
26992699

2700-
taskENTER_CRITICAL();
2700+
portBASE_TYPE_ENTER_CRITICAL();
27012701
{
27022702
/* If null is passed in here then it is the base priority of the task
27032703
* that called uxTaskBasePriorityGet() that is being queried. */
27042704
pxTCB = prvGetTCBFromHandle( xTask );
27052705
uxReturn = pxTCB->uxBasePriority;
27062706
}
2707-
taskEXIT_CRITICAL();
2707+
portBASE_TYPE_EXIT_CRITICAL();
27082708

27092709
traceRETURN_uxTaskBasePriorityGet( uxReturn );
27102710

@@ -3040,12 +3040,12 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
30403040

30413041
traceENTER_vTaskCoreAffinityGet( xTask );
30423042

3043-
taskENTER_CRITICAL();
3043+
portBASE_TYPE_ENTER_CRITICAL();
30443044
{
30453045
pxTCB = prvGetTCBFromHandle( xTask );
30463046
uxCoreAffinityMask = pxTCB->uxCoreAffinityMask;
30473047
}
3048-
taskEXIT_CRITICAL();
3048+
portBASE_TYPE_EXIT_CRITICAL();
30493049

30503050
traceRETURN_vTaskCoreAffinityGet( uxCoreAffinityMask );
30513051

timers.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@
601601
traceENTER_xTimerGetReloadMode( xTimer );
602602

603603
configASSERT( xTimer );
604-
taskENTER_CRITICAL();
604+
portBASE_TYPE_ENTER_CRITICAL();
605605
{
606606
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0U )
607607
{
@@ -614,7 +614,7 @@
614614
xReturn = pdTRUE;
615615
}
616616
}
617-
taskEXIT_CRITICAL();
617+
portBASE_TYPE_EXIT_CRITICAL();
618618

619619
traceRETURN_xTimerGetReloadMode( xReturn );
620620

@@ -1169,7 +1169,7 @@
11691169
configASSERT( xTimer );
11701170

11711171
/* Is the timer in the list of active timers? */
1172-
taskENTER_CRITICAL();
1172+
portBASE_TYPE_ENTER_CRITICAL();
11731173
{
11741174
if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0U )
11751175
{
@@ -1180,7 +1180,7 @@
11801180
xReturn = pdTRUE;
11811181
}
11821182
}
1183-
taskEXIT_CRITICAL();
1183+
portBASE_TYPE_EXIT_CRITICAL();
11841184

11851185
traceRETURN_xTimerIsTimerActive( xReturn );
11861186

0 commit comments

Comments
 (0)