Skip to content

Commit e81ad46

Browse files
refactor: change methods ENTER|EXIT critical (FreeRTOS#1140)
refactor: change methods ENTER|EXIT critical The read and write of BaseType_t are atomic for a number of ports and therefore, do not require taskENTER_CRITICAL/taskEXIT_CRITICAL. This PR introduces portBASE_TYPE_ENTER_CRITICAL and portBASE_TYPE_EXIT_CRITICAL which default to taskENTER_CRITICAL and taskEXIT_CRITICAL. The APIs that read/write BaseType_t are updated to use these new macros. The next change would to be to define portBASE_TYPE_ENTER_CRITICAL and portBASE_TYPE_EXIT_CRITICAL to nothing for ports where BaseType_t read and write are atomic. Signed-off-by: guilherme giacomo simoes <trintaeoitogc@gmail.com>
1 parent 1cb8042 commit e81ad46

File tree

6 files changed

+24
-16
lines changed

6 files changed

+24
-16
lines changed

.github/third_party_tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ team.
1111
| Tool | Website | Getting Started |
1212
|------|---------|-----------------|
1313
| Code Sonar | [Link](https://codesecure.com/our-products/codesonar/) | [Link](https://github.com/CodeSecure-SE/FreeRTOS-Kernel/blob/main/examples/codesonar/README.md) |
14-
| Coverity | [Link](https://www.synopsys.com/software-integrity/security-testing/static-analysis-sast.html) | [Link](../examples/coverity/README.md) |
14+
| Coverity | [Link](https://www.blackduck.com/static-analysis-tools-sast/coverity.html) | [Link](../examples/coverity/README.md) |

examples/coverity/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MISRA Compliance for FreeRTOS-Kernel
22
FreeRTOS-Kernel is MISRA C:2012 compliant. This directory contains a project to
3-
run [Synopsys Coverity](https://www.synopsys.com/software-integrity/security-testing/static-analysis-sast.html)
3+
run [Synopsys Coverity](https://www.blackduck.com/static-analysis-tools-sast/coverity.html)
44
for checking MISRA compliance.
55

66
> **Note**

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)