Skip to content

Commit d0a5ad6

Browse files
Added a macro to tasks.c to check for scheduler suspension uniformly
This commit adds the macro taskIS_SCHEDULER_SUSPENDED() to check for the scheduler state in a uniform manner. Signed-off-by: Sudeep Mohanty <[email protected]>
1 parent eb00a53 commit d0a5ad6

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

tasks.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@
214214

215215
/*-----------------------------------------------------------*/
216216

217+
/* Check if the scheduler is suspended */
218+
#define taskIS_SCHEDULER_SUSPENDED() ( uxSchedulerSuspended > ( UBaseType_t ) 0U )
219+
220+
/*-----------------------------------------------------------*/
221+
217222
/*
218223
* Place the task represented by pxTCB into the appropriate ready list for
219224
* the task. It is inserted at the end of the list.
@@ -387,7 +392,7 @@ const volatile UBaseType_t uxTopUsedPriority = configMAX_PRIORITIES - 1U;
387392
* kernel to move the task from the pending ready list into the real ready list
388393
* when the scheduler is unsuspended. The pending ready list itself can only be
389394
* accessed from a critical section. */
390-
PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended = ( UBaseType_t ) pdFALSE;
395+
PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended = ( UBaseType_t ) 0U;
391396

392397
#if ( configGENERATE_RUN_TIME_STATS == 1 )
393398

@@ -1200,7 +1205,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
12001205
{
12011206
if( pxTCB == pxCurrentTCB )
12021207
{
1203-
configASSERT( uxSchedulerSuspended == 0 );
1208+
configASSERT( !taskIS_SCHEDULER_SUSPENDED() );
12041209
portYIELD_WITHIN_API();
12051210
}
12061211
else
@@ -1223,7 +1228,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
12231228

12241229
configASSERT( pxPreviousWakeTime );
12251230
configASSERT( ( xTimeIncrement > 0U ) );
1226-
configASSERT( uxSchedulerSuspended == 0 );
1231+
configASSERT( !taskIS_SCHEDULER_SUSPENDED() );
12271232

12281233
vTaskSuspendAll();
12291234
{
@@ -1309,7 +1314,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
13091314
/* A delay time of zero just forces a reschedule. */
13101315
if( xTicksToDelay > ( TickType_t ) 0U )
13111316
{
1312-
configASSERT( uxSchedulerSuspended == 0 );
1317+
configASSERT( !taskIS_SCHEDULER_SUSPENDED() );
13131318
vTaskSuspendAll();
13141319
{
13151320
traceTASK_DELAY();
@@ -1748,7 +1753,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
17481753
if( xSchedulerRunning != pdFALSE )
17491754
{
17501755
/* The current task has just been suspended. */
1751-
configASSERT( uxSchedulerSuspended == 0 );
1756+
configASSERT( !taskIS_SCHEDULER_SUSPENDED() );
17521757
portYIELD_WITHIN_API();
17531758
}
17541759
else
@@ -1914,7 +1919,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
19141919
traceTASK_RESUME_FROM_ISR( pxTCB );
19151920

19161921
/* Check the ready lists can be accessed. */
1917-
if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )
1922+
if( !taskIS_SCHEDULER_SUSPENDED() )
19181923
{
19191924
/* Ready lists can be accessed so move the task from the
19201925
* suspended list to the ready list directly. */
@@ -2183,7 +2188,7 @@ BaseType_t xTaskResumeAll( void )
21832188

21842189
/* If uxSchedulerSuspended is zero then this function does not match a
21852190
* previous call to vTaskSuspendAll(). */
2186-
configASSERT( uxSchedulerSuspended );
2191+
configASSERT( taskIS_SCHEDULER_SUSPENDED() );
21872192

21882193
/* It is possible that an ISR caused a task to be removed from an event
21892194
* list while the scheduler was suspended. If this was the case then the
@@ -2194,7 +2199,7 @@ BaseType_t xTaskResumeAll( void )
21942199
{
21952200
--uxSchedulerSuspended;
21962201

2197-
if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )
2202+
if( !taskIS_SCHEDULER_SUSPENDED() )
21982203
{
21992204
if( uxCurrentNumberOfTasks > ( UBaseType_t ) 0U )
22002205
{
@@ -2642,7 +2647,7 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char
26422647
/* Arrange for xTickCount to reach xNextTaskUnblockTime in
26432648
* xTaskIncrementTick() when the scheduler resumes. This ensures
26442649
* that any delayed tasks are resumed at the correct time. */
2645-
configASSERT( uxSchedulerSuspended );
2650+
configASSERT( taskIS_SCHEDULER_SUSPENDED() );
26462651
configASSERT( xTicksToJump != ( TickType_t ) 0 );
26472652

26482653
/* Prevent the tick interrupt modifying xPendedTicks simultaneously. */
@@ -2671,7 +2676,7 @@ BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp )
26712676

26722677
/* Must not be called with the scheduler suspended as the implementation
26732678
* relies on xPendedTicks being wound down to 0 in xTaskResumeAll(). */
2674-
configASSERT( uxSchedulerSuspended == 0 );
2679+
configASSERT( !taskIS_SCHEDULER_SUSPENDED() );
26752680

26762681
/* Use xPendedTicks to mimic xTicksToCatchUp number of ticks occurring when
26772682
* the scheduler is suspended so the ticks are executed in xTaskResumeAll(). */
@@ -2780,7 +2785,7 @@ BaseType_t xTaskIncrementTick( void )
27802785
* tasks to be unblocked. */
27812786
traceTASK_INCREMENT_TICK( xTickCount );
27822787

2783-
if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )
2788+
if( !taskIS_SCHEDULER_SUSPENDED() )
27842789
{
27852790
/* Minor optimisation. The tick count cannot change in this
27862791
* block. */
@@ -3060,7 +3065,7 @@ BaseType_t xTaskIncrementTick( void )
30603065

30613066
void vTaskSwitchContext( void )
30623067
{
3063-
if( uxSchedulerSuspended != ( UBaseType_t ) pdFALSE )
3068+
if( taskIS_SCHEDULER_SUSPENDED() )
30643069
{
30653070
/* The scheduler is currently suspended - do not allow a context
30663071
* switch. */
@@ -3165,7 +3170,7 @@ void vTaskPlaceOnUnorderedEventList( List_t * pxEventList,
31653170

31663171
/* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. It is used by
31673172
* the event groups implementation. */
3168-
configASSERT( uxSchedulerSuspended != 0 );
3173+
configASSERT( taskIS_SCHEDULER_SUSPENDED() );
31693174

31703175
/* Store the item value in the event list item. It is safe to access the
31713176
* event list item here as interrupts won't access the event list item of a
@@ -3240,7 +3245,7 @@ BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList )
32403245
configASSERT( pxUnblockedTCB );
32413246
listREMOVE_ITEM( &( pxUnblockedTCB->xEventListItem ) );
32423247

3243-
if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )
3248+
if( !taskIS_SCHEDULER_SUSPENDED() )
32443249
{
32453250
listREMOVE_ITEM( &( pxUnblockedTCB->xStateListItem ) );
32463251
prvAddTaskToReadyList( pxUnblockedTCB );
@@ -3293,7 +3298,7 @@ void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem,
32933298

32943299
/* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. It is used by
32953300
* the event flags implementation. */
3296-
configASSERT( uxSchedulerSuspended != pdFALSE );
3301+
configASSERT( taskIS_SCHEDULER_SUSPENDED() );
32973302

32983303
/* Store the new item value in the event list. */
32993304
listSET_LIST_ITEM_VALUE( pxEventListItem, xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE );
@@ -4093,7 +4098,7 @@ static void prvResetNextTaskUnblockTime( void )
40934098
}
40944099
else
40954100
{
4096-
if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )
4101+
if( !taskIS_SCHEDULER_SUSPENDED() )
40974102
{
40984103
xReturn = taskSCHEDULER_RUNNING;
40994104
}
@@ -5113,7 +5118,7 @@ TickType_t uxTaskResetEventItemValue( void )
51135118
/* The task should not have been on an event list. */
51145119
configASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL );
51155120

5116-
if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )
5121+
if( !taskIS_SCHEDULER_SUSPENDED() )
51175122
{
51185123
listREMOVE_ITEM( &( pxTCB->xStateListItem ) );
51195124
prvAddTaskToReadyList( pxTCB );
@@ -5204,7 +5209,7 @@ TickType_t uxTaskResetEventItemValue( void )
52045209
/* The task should not have been on an event list. */
52055210
configASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL );
52065211

5207-
if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE )
5212+
if( !taskIS_SCHEDULER_SUSPENDED() )
52085213
{
52095214
listREMOVE_ITEM( &( pxTCB->xStateListItem ) );
52105215
prvAddTaskToReadyList( pxTCB );

0 commit comments

Comments
 (0)