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
}
@@ -3880,7 +3883,7 @@ void vTaskSuspendAll( void )
3880
3883
ulState = portSET_INTERRUPT_MASK ();
3881
3884
3882
3885
/* This must never be called from inside a critical section. */
3883
- configASSERT ( portGET_CRITICAL_NESTING_COUNT () == 0 );
3886
+ configASSERT ( portGET_CRITICAL_NESTING_COUNT ( portGET_CORE_ID () ) == 0 );
3884
3887
3885
3888
/* portSOFTWARE_BARRIER() is only implemented for emulated/simulated ports that
3886
3889
* do not otherwise exhibit real time behaviour. */
@@ -4003,8 +4006,7 @@ BaseType_t xTaskResumeAll( void )
4003
4006
* tasks from this list into their appropriate ready list. */
4004
4007
taskENTER_CRITICAL ();
4005
4008
{
4006
- BaseType_t xCoreID ;
4007
- xCoreID = ( BaseType_t ) portGET_CORE_ID ();
4009
+ const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID ();
4008
4010
4009
4011
/* If uxSchedulerSuspended is zero then this function does not match a
4010
4012
* previous call to vTaskSuspendAll(). */
@@ -5187,7 +5189,7 @@ BaseType_t xTaskIncrementTick( void )
5187
5189
/* vTaskSwitchContext() must never be called from within a critical section.
5188
5190
* This is not necessarily true for single core FreeRTOS, but it is for this
5189
5191
* SMP port. */
5190
- configASSERT ( portGET_CRITICAL_NESTING_COUNT () == 0 );
5192
+ configASSERT ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0 );
5191
5193
5192
5194
if ( uxSchedulerSuspended != ( UBaseType_t ) 0U )
5193
5195
{
@@ -6937,16 +6939,24 @@ static void prvResetNextTaskUnblockTime( void )
6937
6939
*/
6938
6940
void vTaskYieldWithinAPI ( void )
6939
6941
{
6942
+ UBaseType_t ulState ;
6943
+
6940
6944
traceENTER_vTaskYieldWithinAPI ();
6941
6945
6942
- if ( portGET_CRITICAL_NESTING_COUNT () == 0U )
6943
- {
6944
- portYIELD ();
6945
- }
6946
- else
6946
+ ulState = portSET_INTERRUPT_MASK ();
6947
6947
{
6948
- xYieldPendings [ portGET_CORE_ID () ] = pdTRUE ;
6948
+ const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID ();
6949
+
6950
+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0U )
6951
+ {
6952
+ portYIELD ();
6953
+ }
6954
+ else
6955
+ {
6956
+ xYieldPendings [ xCoreID ] = pdTRUE ;
6957
+ }
6949
6958
}
6959
+ portCLEAR_INTERRUPT_MASK ( ulState );
6950
6960
6951
6961
traceRETURN_vTaskYieldWithinAPI ();
6952
6962
}
@@ -6995,40 +7005,43 @@ static void prvResetNextTaskUnblockTime( void )
6995
7005
traceENTER_vTaskEnterCritical ();
6996
7006
6997
7007
portDISABLE_INTERRUPTS ();
6998
-
6999
- if ( xSchedulerRunning != pdFALSE )
7000
7008
{
7001
- if ( portGET_CRITICAL_NESTING_COUNT () == 0U )
7002
- {
7003
- portGET_TASK_LOCK ();
7004
- portGET_ISR_LOCK ();
7005
- }
7006
-
7007
- portINCREMENT_CRITICAL_NESTING_COUNT ();
7009
+ const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID ();
7008
7010
7009
- /* This is not the interrupt safe version of the enter critical
7010
- * function so assert() if it is being called from an interrupt
7011
- * context. Only API functions that end in "FromISR" can be used in an
7012
- * interrupt. Only assert if the critical nesting count is 1 to
7013
- * protect against recursive calls if the assert function also uses a
7014
- * critical section. */
7015
- if ( portGET_CRITICAL_NESTING_COUNT () == 1U )
7011
+ if ( xSchedulerRunning != pdFALSE )
7016
7012
{
7017
- portASSERT_IF_IN_ISR ();
7013
+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0U )
7014
+ {
7015
+ portGET_TASK_LOCK ();
7016
+ portGET_ISR_LOCK ();
7017
+ }
7018
7018
7019
- if ( uxSchedulerSuspended == 0U )
7019
+ portINCREMENT_CRITICAL_NESTING_COUNT ( xCoreID );
7020
+
7021
+ /* This is not the interrupt safe version of the enter critical
7022
+ * function so assert() if it is being called from an interrupt
7023
+ * context. Only API functions that end in "FromISR" can be used in an
7024
+ * interrupt. Only assert if the critical nesting count is 1 to
7025
+ * protect against recursive calls if the assert function also uses a
7026
+ * critical section. */
7027
+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 1U )
7020
7028
{
7021
- /* The only time there would be a problem is if this is called
7022
- * before a context switch and vTaskExitCritical() is called
7023
- * after pxCurrentTCB changes. Therefore this should not be
7024
- * used within vTaskSwitchContext(). */
7025
- prvCheckForRunStateChange ();
7029
+ portASSERT_IF_IN_ISR ();
7030
+
7031
+ if ( uxSchedulerSuspended == 0U )
7032
+ {
7033
+ /* The only time there would be a problem is if this is called
7034
+ * before a context switch and vTaskExitCritical() is called
7035
+ * after pxCurrentTCB changes. Therefore this should not be
7036
+ * used within vTaskSwitchContext(). */
7037
+ prvCheckForRunStateChange ();
7038
+ }
7026
7039
}
7027
7040
}
7028
- }
7029
- else
7030
- {
7031
- mtCOVERAGE_TEST_MARKER ();
7041
+ else
7042
+ {
7043
+ mtCOVERAGE_TEST_MARKER ();
7044
+ }
7032
7045
}
7033
7046
7034
7047
traceRETURN_vTaskEnterCritical ();
@@ -7043,19 +7056,20 @@ static void prvResetNextTaskUnblockTime( void )
7043
7056
UBaseType_t vTaskEnterCriticalFromISR ( void )
7044
7057
{
7045
7058
UBaseType_t uxSavedInterruptStatus = 0 ;
7059
+ const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID ();
7046
7060
7047
7061
traceENTER_vTaskEnterCriticalFromISR ();
7048
7062
7049
7063
if ( xSchedulerRunning != pdFALSE )
7050
7064
{
7051
7065
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR ();
7052
7066
7053
- if ( portGET_CRITICAL_NESTING_COUNT () == 0U )
7067
+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0U )
7054
7068
{
7055
7069
portGET_ISR_LOCK ();
7056
7070
}
7057
7071
7058
- portINCREMENT_CRITICAL_NESTING_COUNT ();
7072
+ portINCREMENT_CRITICAL_NESTING_COUNT ( xCoreID );
7059
7073
}
7060
7074
else
7061
7075
{
@@ -7119,28 +7133,30 @@ static void prvResetNextTaskUnblockTime( void )
7119
7133
7120
7134
void vTaskExitCritical ( void )
7121
7135
{
7136
+ const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID ();
7137
+
7122
7138
traceENTER_vTaskExitCritical ();
7123
7139
7124
7140
if ( xSchedulerRunning != pdFALSE )
7125
7141
{
7126
7142
/* If critical nesting count is zero then this function
7127
7143
* does not match a previous call to vTaskEnterCritical(). */
7128
- configASSERT ( portGET_CRITICAL_NESTING_COUNT () > 0U );
7144
+ configASSERT ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) > 0U );
7129
7145
7130
7146
/* This function should not be called in ISR. Use vTaskExitCriticalFromISR
7131
7147
* to exit critical section from ISR. */
7132
7148
portASSERT_IF_IN_ISR ();
7133
7149
7134
- if ( portGET_CRITICAL_NESTING_COUNT () > 0U )
7150
+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) > 0U )
7135
7151
{
7136
- portDECREMENT_CRITICAL_NESTING_COUNT ();
7152
+ portDECREMENT_CRITICAL_NESTING_COUNT ( xCoreID );
7137
7153
7138
- if ( portGET_CRITICAL_NESTING_COUNT () == 0U )
7154
+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0U )
7139
7155
{
7140
7156
BaseType_t xYieldCurrentTask ;
7141
7157
7142
7158
/* Get the xYieldPending stats inside the critical section. */
7143
- xYieldCurrentTask = xYieldPendings [ portGET_CORE_ID () ];
7159
+ xYieldCurrentTask = xYieldPendings [ xCoreID ];
7144
7160
7145
7161
portRELEASE_ISR_LOCK ();
7146
7162
portRELEASE_TASK_LOCK ();
@@ -7180,19 +7196,23 @@ static void prvResetNextTaskUnblockTime( void )
7180
7196
7181
7197
void vTaskExitCriticalFromISR ( UBaseType_t uxSavedInterruptStatus )
7182
7198
{
7199
+ BaseType_t xCoreID ;
7200
+
7183
7201
traceENTER_vTaskExitCriticalFromISR ( uxSavedInterruptStatus );
7184
7202
7185
7203
if ( xSchedulerRunning != pdFALSE )
7186
7204
{
7205
+ xCoreID = ( BaseType_t ) portGET_CORE_ID ();
7206
+
7187
7207
/* If critical nesting count is zero then this function
7188
7208
* does not match a previous call to vTaskEnterCritical(). */
7189
- configASSERT ( portGET_CRITICAL_NESTING_COUNT () > 0U );
7209
+ configASSERT ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) > 0U );
7190
7210
7191
- if ( portGET_CRITICAL_NESTING_COUNT () > 0U )
7211
+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) > 0U )
7192
7212
{
7193
- portDECREMENT_CRITICAL_NESTING_COUNT ();
7213
+ portDECREMENT_CRITICAL_NESTING_COUNT ( xCoreID );
7194
7214
7195
- if ( portGET_CRITICAL_NESTING_COUNT () == 0U )
7215
+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0U )
7196
7216
{
7197
7217
portRELEASE_ISR_LOCK ();
7198
7218
portCLEAR_INTERRUPT_MASK_FROM_ISR ( uxSavedInterruptStatus );
0 commit comments