Skip to content
24 changes: 12 additions & 12 deletions include/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ typedef struct xLIST
} \
\
( pxItemToRemove )->pxContainer = NULL; \
( pxList->uxNumberOfItems )--; \
( ( pxList )->uxNumberOfItems ) -= ( UBaseType_t ) 1U; \

@htibosch htibosch Feb 10, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One simplification:

-    ( ( pxList )->uxNumberOfItems ) -= ( UBaseType_t ) 1U; 
+    ( ( pxList )->uxNumberOfItems ) -= 1U; 

I think that the cast is not necessary. Have a try.

Also try:

-    xNumOfOverflows += ( BaseType_t ) 1;   
+    xNumOfOverflows += 1;   

EDIT Ok, reading back I see that a compiler doesn't agree with an implicit cast from 1U to UBaseType_t. That's a pity.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that BaseType_t can be a different size from "unsigned", which means this will work fine with some types as BaseType_t but not others. These cases are tricky because compiling only with one type for BaseType_t will not expose all the problems !

} while( 0 )

/*
Expand Down Expand Up @@ -363,17 +363,17 @@ typedef struct xLIST
\
/* Insert a new list item into ( pxList ), but rather than sort the list, \
* makes the new list item the last item to be removed by a call to \
* listGET_OWNER_OF_NEXT_ENTRY(). */ \
( pxNewListItem )->pxNext = pxIndex; \
( pxNewListItem )->pxPrevious = pxIndex->pxPrevious; \
\
pxIndex->pxPrevious->pxNext = ( pxNewListItem ); \
pxIndex->pxPrevious = ( pxNewListItem ); \
\
/* Remember which list the item is in. */ \
( pxNewListItem )->pxContainer = ( pxList ); \
\
( ( pxList )->uxNumberOfItems )++; \
* listGET_OWNER_OF_NEXT_ENTRY(). */ \
( pxNewListItem )->pxNext = pxIndex; \
( pxNewListItem )->pxPrevious = pxIndex->pxPrevious; \
\
pxIndex->pxPrevious->pxNext = ( pxNewListItem ); \
pxIndex->pxPrevious = ( pxNewListItem ); \
\
/* Remember which list the item is in. */ \
( pxNewListItem )->pxContainer = ( pxList ); \
\
( ( pxList )->uxNumberOfItems ) += ( UBaseType_t ) 1U; \
} while( 0 )

/*
Expand Down
9 changes: 4 additions & 5 deletions list.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void vListInsertEnd( List_t * const pxList,
/* Remember which list the item is in. */
pxNewListItem->pxContainer = pxList;

( pxList->uxNumberOfItems )++;
( pxList->uxNumberOfItems ) += ( UBaseType_t ) 1U;

traceRETURN_vListInsertEnd();
}
Expand Down Expand Up @@ -205,12 +205,13 @@ void vListInsert( List_t * const pxList,
* item later. */
pxNewListItem->pxContainer = pxList;

( pxList->uxNumberOfItems )++;
( pxList->uxNumberOfItems ) += ( UBaseType_t ) 1U;

traceRETURN_vListInsert();
}
/*-----------------------------------------------------------*/


UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
{
/* The list item knows which list it is in. Obtain the list from the list
Expand All @@ -219,8 +220,6 @@ UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )

traceENTER_uxListRemove( pxItemToRemove );



pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;

Expand All @@ -238,7 +237,7 @@ UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
}

pxItemToRemove->pxContainer = NULL;
( pxList->uxNumberOfItems )--;
( pxList->uxNumberOfItems ) -= ( UBaseType_t ) 1U;

traceRETURN_uxListRemove( pxList->uxNumberOfItems );

Expand Down
10 changes: 5 additions & 5 deletions tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
pxTemp = pxDelayedTaskList; \
pxDelayedTaskList = pxOverflowDelayedTaskList; \
pxOverflowDelayedTaskList = pxTemp; \
xNumOfOverflows++; \
xNumOfOverflows += ( BaseType_t ) 1; \
prvResetNextTaskUnblockTime(); \
} while( 0 )

Expand Down Expand Up @@ -2021,7 +2021,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
* updated. */
taskENTER_CRITICAL();
{
uxCurrentNumberOfTasks++;
uxCurrentNumberOfTasks += ( UBaseType_t ) 1U;

if( pxCurrentTCB == NULL )
{
Expand Down Expand Up @@ -3815,7 +3815,7 @@ void vTaskSuspendAll( void )

/* The scheduler is suspended if uxSchedulerSuspended is non-zero. An increment
* is used to allow calls to vTaskSuspendAll() to nest. */
++uxSchedulerSuspended;
uxSchedulerSuspended += ( UBaseType_t ) 1U;

/* Enforces ordering for ports and optimised compilers that may otherwise place
* the above increment elsewhere. */
Expand Down Expand Up @@ -3968,7 +3968,7 @@ BaseType_t xTaskResumeAll( void )
* previous call to vTaskSuspendAll(). */
configASSERT( uxSchedulerSuspended != 0U );

--uxSchedulerSuspended;
uxSchedulerSuspended -= ( UBaseType_t ) 1U;
portRELEASE_TASK_LOCK();

if( uxSchedulerSuspended == ( UBaseType_t ) 0U )
Expand Down Expand Up @@ -4968,7 +4968,7 @@ BaseType_t xTaskIncrementTick( void )
}
else
{
++xPendedTicks;
xPendedTicks += 1U;

/* The tick hook gets called at regular intervals, even if the
* scheduler is locked. */
Expand Down