317
317
#define taskATTRIBUTE_IS_IDLE ( UBaseType_t ) ( 1U << 0U )
318
318
319
319
#if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) )
320
- #define portGET_CRITICAL_NESTING_COUNT () ( pxCurrentTCBs[ portGET_CORE_ID( ) ]->uxCriticalNesting )
321
- #define portSET_CRITICAL_NESTING_COUNT ( x ) ( pxCurrentTCBs[ portGET_CORE_ID( ) ]->uxCriticalNesting = ( x ) )
322
- #define portINCREMENT_CRITICAL_NESTING_COUNT () ( pxCurrentTCBs[ portGET_CORE_ID( ) ]->uxCriticalNesting++ )
323
- #define portDECREMENT_CRITICAL_NESTING_COUNT () ( pxCurrentTCBs[ portGET_CORE_ID( ) ]->uxCriticalNesting-- )
320
+ #define portGET_CRITICAL_NESTING_COUNT ( xCoreID ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting )
321
+ #define portSET_CRITICAL_NESTING_COUNT ( xCoreID , x ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting = ( x ) )
322
+ #define portINCREMENT_CRITICAL_NESTING_COUNT ( xCoreID ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting++ )
323
+ #define portDECREMENT_CRITICAL_NESTING_COUNT ( xCoreID ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting-- )
324
324
#endif /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) ) */
325
325
326
326
#define taskBITS_PER_BYTE ( ( size_t ) 8 )
@@ -807,13 +807,14 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
807
807
{
808
808
UBaseType_t uxPrevCriticalNesting ;
809
809
const TCB_t * pxThisTCB ;
810
+ BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID ();
810
811
811
812
/* This must only be called from within a task. */
812
813
portASSERT_IF_IN_ISR ();
813
814
814
815
/* This function is always called with interrupts disabled
815
816
* so this is safe. */
816
- pxThisTCB = pxCurrentTCBs [ portGET_CORE_ID () ];
817
+ pxThisTCB = pxCurrentTCBs [ xCoreID ];
817
818
818
819
while ( pxThisTCB -> xTaskRunState == taskTASK_SCHEDULED_TO_YIELD )
819
820
{
@@ -825,11 +826,11 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
825
826
* the suspension and critical nesting counts, as well as release
826
827
* and reacquire the correct locks. And then, do it all over again
827
828
* if our state changed again during the reacquisition. */
828
- uxPrevCriticalNesting = portGET_CRITICAL_NESTING_COUNT ();
829
+ uxPrevCriticalNesting = portGET_CRITICAL_NESTING_COUNT ( xCoreID );
829
830
830
831
if ( uxPrevCriticalNesting > 0U )
831
832
{
832
- portSET_CRITICAL_NESTING_COUNT ( 0U );
833
+ portSET_CRITICAL_NESTING_COUNT ( xCoreID , 0U );
833
834
portRELEASE_ISR_LOCK ();
834
835
}
835
836
else
@@ -854,8 +855,9 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
854
855
portDISABLE_INTERRUPTS ();
855
856
portGET_TASK_LOCK ();
856
857
portGET_ISR_LOCK ();
858
+ xCoreID = ( BaseType_t ) portGET_CORE_ID ();
857
859
858
- portSET_CRITICAL_NESTING_COUNT ( uxPrevCriticalNesting );
860
+ portSET_CRITICAL_NESTING_COUNT ( xCoreID , uxPrevCriticalNesting );
859
861
860
862
if ( uxPrevCriticalNesting == 0U )
861
863
{
@@ -874,13 +876,14 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
874
876
BaseType_t xCurrentCoreTaskPriority ;
875
877
BaseType_t xLowestPriorityCore = ( BaseType_t ) - 1 ;
876
878
BaseType_t xCoreID ;
879
+ const BaseType_t xCurrentCoreID = portGET_CORE_ID ();
877
880
878
881
#if ( configRUN_MULTIPLE_PRIORITIES == 0 )
879
882
BaseType_t xYieldCount = 0 ;
880
883
#endif /* #if ( configRUN_MULTIPLE_PRIORITIES == 0 ) */
881
884
882
885
/* This must be called from a critical section. */
883
- configASSERT ( portGET_CRITICAL_NESTING_COUNT () > 0U );
886
+ configASSERT ( portGET_CRITICAL_NESTING_COUNT ( xCurrentCoreID ) > 0U );
884
887
885
888
#if ( configRUN_MULTIPLE_PRIORITIES == 0 )
886
889
@@ -969,11 +972,11 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
969
972
970
973
#if ( configRUN_MULTIPLE_PRIORITIES == 0 )
971
974
/* Verify that the calling core always yields to higher priority tasks. */
972
- if ( ( ( pxCurrentTCBs [ portGET_CORE_ID () ]-> uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) == 0U ) &&
973
- ( pxTCB -> uxPriority > pxCurrentTCBs [ portGET_CORE_ID () ]-> uxPriority ) )
975
+ if ( ( ( pxCurrentTCBs [ xCurrentCoreID ]-> uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) == 0U ) &&
976
+ ( pxTCB -> uxPriority > pxCurrentTCBs [ xCurrentCoreID ]-> uxPriority ) )
974
977
{
975
- configASSERT ( ( xYieldPendings [ portGET_CORE_ID () ] == pdTRUE ) ||
976
- ( taskTASK_IS_RUNNING ( pxCurrentTCBs [ portGET_CORE_ID () ] ) == pdFALSE ) );
978
+ configASSERT ( ( xYieldPendings [ xCurrentCoreID ] == pdTRUE ) ||
979
+ ( taskTASK_IS_RUNNING ( pxCurrentTCBs [ xCurrentCoreID ] ) == pdFALSE ) );
977
980
}
978
981
#endif
979
982
}
@@ -3865,7 +3868,7 @@ void vTaskSuspendAll( void )
3865
3868
ulState = portSET_INTERRUPT_MASK ();
3866
3869
3867
3870
/* This must never be called from inside a critical section. */
3868
- configASSERT ( portGET_CRITICAL_NESTING_COUNT () == 0 );
3871
+ configASSERT ( portGET_CRITICAL_NESTING_COUNT ( portGET_CORE_ID () ) == 0 );
3869
3872
3870
3873
/* portSOFTWARE_BARRIER() is only implemented for emulated/simulated ports that
3871
3874
* do not otherwise exhibit real time behaviour. */
@@ -3988,8 +3991,7 @@ BaseType_t xTaskResumeAll( void )
3988
3991
* tasks from this list into their appropriate ready list. */
3989
3992
taskENTER_CRITICAL ();
3990
3993
{
3991
- BaseType_t xCoreID ;
3992
- xCoreID = ( BaseType_t ) portGET_CORE_ID ();
3994
+ const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID ();
3993
3995
3994
3996
/* If uxSchedulerSuspended is zero then this function does not match a
3995
3997
* previous call to vTaskSuspendAll(). */
@@ -5172,7 +5174,7 @@ BaseType_t xTaskIncrementTick( void )
5172
5174
/* vTaskSwitchContext() must never be called from within a critical section.
5173
5175
* This is not necessarily true for single core FreeRTOS, but it is for this
5174
5176
* SMP port. */
5175
- configASSERT ( portGET_CRITICAL_NESTING_COUNT () == 0 );
5177
+ configASSERT ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0 );
5176
5178
5177
5179
if ( uxSchedulerSuspended != ( UBaseType_t ) 0U )
5178
5180
{
@@ -6922,16 +6924,24 @@ static void prvResetNextTaskUnblockTime( void )
6922
6924
*/
6923
6925
void vTaskYieldWithinAPI ( void )
6924
6926
{
6927
+ UBaseType_t ulState ;
6928
+
6925
6929
traceENTER_vTaskYieldWithinAPI ();
6926
6930
6927
- if ( portGET_CRITICAL_NESTING_COUNT () == 0U )
6928
- {
6929
- portYIELD ();
6930
- }
6931
- else
6931
+ ulState = portSET_INTERRUPT_MASK ();
6932
6932
{
6933
- xYieldPendings [ portGET_CORE_ID () ] = pdTRUE ;
6933
+ const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID ();
6934
+
6935
+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0U )
6936
+ {
6937
+ portYIELD ();
6938
+ }
6939
+ else
6940
+ {
6941
+ xYieldPendings [ xCoreID ] = pdTRUE ;
6942
+ }
6934
6943
}
6944
+ portCLEAR_INTERRUPT_MASK ( ulState );
6935
6945
6936
6946
traceRETURN_vTaskYieldWithinAPI ();
6937
6947
}
@@ -6980,40 +6990,43 @@ static void prvResetNextTaskUnblockTime( void )
6980
6990
traceENTER_vTaskEnterCritical ();
6981
6991
6982
6992
portDISABLE_INTERRUPTS ();
6983
-
6984
- if ( xSchedulerRunning != pdFALSE )
6985
6993
{
6986
- if ( portGET_CRITICAL_NESTING_COUNT () == 0U )
6987
- {
6988
- portGET_TASK_LOCK ();
6989
- portGET_ISR_LOCK ();
6990
- }
6991
-
6992
- portINCREMENT_CRITICAL_NESTING_COUNT ();
6994
+ const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID ();
6993
6995
6994
- /* This is not the interrupt safe version of the enter critical
6995
- * function so assert() if it is being called from an interrupt
6996
- * context. Only API functions that end in "FromISR" can be used in an
6997
- * interrupt. Only assert if the critical nesting count is 1 to
6998
- * protect against recursive calls if the assert function also uses a
6999
- * critical section. */
7000
- if ( portGET_CRITICAL_NESTING_COUNT () == 1U )
6996
+ if ( xSchedulerRunning != pdFALSE )
7001
6997
{
7002
- portASSERT_IF_IN_ISR ();
6998
+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0U )
6999
+ {
7000
+ portGET_TASK_LOCK ();
7001
+ portGET_ISR_LOCK ();
7002
+ }
7003
7003
7004
- if ( uxSchedulerSuspended == 0U )
7004
+ portINCREMENT_CRITICAL_NESTING_COUNT ( xCoreID );
7005
+
7006
+ /* This is not the interrupt safe version of the enter critical
7007
+ * function so assert() if it is being called from an interrupt
7008
+ * context. Only API functions that end in "FromISR" can be used in an
7009
+ * interrupt. Only assert if the critical nesting count is 1 to
7010
+ * protect against recursive calls if the assert function also uses a
7011
+ * critical section. */
7012
+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 1U )
7005
7013
{
7006
- /* The only time there would be a problem is if this is called
7007
- * before a context switch and vTaskExitCritical() is called
7008
- * after pxCurrentTCB changes. Therefore this should not be
7009
- * used within vTaskSwitchContext(). */
7010
- prvCheckForRunStateChange ();
7014
+ portASSERT_IF_IN_ISR ();
7015
+
7016
+ if ( uxSchedulerSuspended == 0U )
7017
+ {
7018
+ /* The only time there would be a problem is if this is called
7019
+ * before a context switch and vTaskExitCritical() is called
7020
+ * after pxCurrentTCB changes. Therefore this should not be
7021
+ * used within vTaskSwitchContext(). */
7022
+ prvCheckForRunStateChange ();
7023
+ }
7011
7024
}
7012
7025
}
7013
- }
7014
- else
7015
- {
7016
- mtCOVERAGE_TEST_MARKER ();
7026
+ else
7027
+ {
7028
+ mtCOVERAGE_TEST_MARKER ();
7029
+ }
7017
7030
}
7018
7031
7019
7032
traceRETURN_vTaskEnterCritical ();
@@ -7028,19 +7041,20 @@ static void prvResetNextTaskUnblockTime( void )
7028
7041
UBaseType_t vTaskEnterCriticalFromISR ( void )
7029
7042
{
7030
7043
UBaseType_t uxSavedInterruptStatus = 0 ;
7044
+ const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID ();
7031
7045
7032
7046
traceENTER_vTaskEnterCriticalFromISR ();
7033
7047
7034
7048
if ( xSchedulerRunning != pdFALSE )
7035
7049
{
7036
7050
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR ();
7037
7051
7038
- if ( portGET_CRITICAL_NESTING_COUNT () == 0U )
7052
+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0U )
7039
7053
{
7040
7054
portGET_ISR_LOCK ();
7041
7055
}
7042
7056
7043
- portINCREMENT_CRITICAL_NESTING_COUNT ();
7057
+ portINCREMENT_CRITICAL_NESTING_COUNT ( xCoreID );
7044
7058
}
7045
7059
else
7046
7060
{
@@ -7104,28 +7118,30 @@ static void prvResetNextTaskUnblockTime( void )
7104
7118
7105
7119
void vTaskExitCritical ( void )
7106
7120
{
7121
+ const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID ();
7122
+
7107
7123
traceENTER_vTaskExitCritical ();
7108
7124
7109
7125
if ( xSchedulerRunning != pdFALSE )
7110
7126
{
7111
7127
/* If critical nesting count is zero then this function
7112
7128
* does not match a previous call to vTaskEnterCritical(). */
7113
- configASSERT ( portGET_CRITICAL_NESTING_COUNT () > 0U );
7129
+ configASSERT ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) > 0U );
7114
7130
7115
7131
/* This function should not be called in ISR. Use vTaskExitCriticalFromISR
7116
7132
* to exit critical section from ISR. */
7117
7133
portASSERT_IF_IN_ISR ();
7118
7134
7119
- if ( portGET_CRITICAL_NESTING_COUNT () > 0U )
7135
+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) > 0U )
7120
7136
{
7121
- portDECREMENT_CRITICAL_NESTING_COUNT ();
7137
+ portDECREMENT_CRITICAL_NESTING_COUNT ( xCoreID );
7122
7138
7123
- if ( portGET_CRITICAL_NESTING_COUNT () == 0U )
7139
+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0U )
7124
7140
{
7125
7141
BaseType_t xYieldCurrentTask ;
7126
7142
7127
7143
/* Get the xYieldPending stats inside the critical section. */
7128
- xYieldCurrentTask = xYieldPendings [ portGET_CORE_ID () ];
7144
+ xYieldCurrentTask = xYieldPendings [ xCoreID ];
7129
7145
7130
7146
portRELEASE_ISR_LOCK ();
7131
7147
portRELEASE_TASK_LOCK ();
@@ -7165,19 +7181,23 @@ static void prvResetNextTaskUnblockTime( void )
7165
7181
7166
7182
void vTaskExitCriticalFromISR ( UBaseType_t uxSavedInterruptStatus )
7167
7183
{
7184
+ BaseType_t xCoreID ;
7185
+
7168
7186
traceENTER_vTaskExitCriticalFromISR ( uxSavedInterruptStatus );
7169
7187
7170
7188
if ( xSchedulerRunning != pdFALSE )
7171
7189
{
7190
+ xCoreID = ( BaseType_t ) portGET_CORE_ID ();
7191
+
7172
7192
/* If critical nesting count is zero then this function
7173
7193
* does not match a previous call to vTaskEnterCritical(). */
7174
- configASSERT ( portGET_CRITICAL_NESTING_COUNT () > 0U );
7194
+ configASSERT ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) > 0U );
7175
7195
7176
- if ( portGET_CRITICAL_NESTING_COUNT () > 0U )
7196
+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) > 0U )
7177
7197
{
7178
- portDECREMENT_CRITICAL_NESTING_COUNT ();
7198
+ portDECREMENT_CRITICAL_NESTING_COUNT ( xCoreID );
7179
7199
7180
- if ( portGET_CRITICAL_NESTING_COUNT () == 0U )
7200
+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0U )
7181
7201
{
7182
7202
portRELEASE_ISR_LOCK ();
7183
7203
portCLEAR_INTERRUPT_MASK_FROM_ISR ( uxSavedInterruptStatus );
0 commit comments