317317#define taskATTRIBUTE_IS_IDLE ( UBaseType_t ) ( 1U << 0U )
318318
319319#if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) )
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-- )
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-- )
324324#endif /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) ) */
325325
326326#define taskBITS_PER_BYTE ( ( size_t ) 8 )
@@ -6941,18 +6941,24 @@ static void prvResetNextTaskUnblockTime( void )
69416941 */
69426942 void vTaskYieldWithinAPI ( void )
69436943 {
6944- const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID () ;
6944+ UBaseType_t ulState ;
69456945
69466946 traceENTER_vTaskYieldWithinAPI ();
69476947
6948- if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0U )
6948+ ulState = portSET_INTERRUPT_MASK ();
69496949 {
6950- portYIELD ();
6951- }
6952- else
6953- {
6954- xYieldPendings [ xCoreID ] = pdTRUE ;
6950+ const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID ();
6951+
6952+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0U )
6953+ {
6954+ portYIELD ();
6955+ }
6956+ else
6957+ {
6958+ xYieldPendings [ xCoreID ] = pdTRUE ;
6959+ }
69556960 }
6961+ portCLEAR_INTERRUPT_MASK ( ulState );
69566962
69576963 traceRETURN_vTaskYieldWithinAPI ();
69586964 }
@@ -7001,42 +7007,43 @@ static void prvResetNextTaskUnblockTime( void )
70017007 traceENTER_vTaskEnterCritical ();
70027008
70037009 portDISABLE_INTERRUPTS ();
7004-
7005- const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID ();
7006-
7007- if ( xSchedulerRunning != pdFALSE )
70087010 {
7009- if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0U )
7010- {
7011- portGET_TASK_LOCK ();
7012- portGET_ISR_LOCK ();
7013- }
7014-
7015- portINCREMENT_CRITICAL_NESTING_COUNT ( xCoreID );
7011+ const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID ();
70167012
7017- /* This is not the interrupt safe version of the enter critical
7018- * function so assert() if it is being called from an interrupt
7019- * context. Only API functions that end in "FromISR" can be used in an
7020- * interrupt. Only assert if the critical nesting count is 1 to
7021- * protect against recursive calls if the assert function also uses a
7022- * critical section. */
7023- if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 1U )
7013+ if ( xSchedulerRunning != pdFALSE )
70247014 {
7025- portASSERT_IF_IN_ISR ();
7015+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0U )
7016+ {
7017+ portGET_TASK_LOCK ();
7018+ portGET_ISR_LOCK ();
7019+ }
70267020
7027- if ( uxSchedulerSuspended == 0U )
7021+ portINCREMENT_CRITICAL_NESTING_COUNT ( xCoreID );
7022+
7023+ /* This is not the interrupt safe version of the enter critical
7024+ * function so assert() if it is being called from an interrupt
7025+ * context. Only API functions that end in "FromISR" can be used in an
7026+ * interrupt. Only assert if the critical nesting count is 1 to
7027+ * protect against recursive calls if the assert function also uses a
7028+ * critical section. */
7029+ if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 1U )
70287030 {
7029- /* The only time there would be a problem is if this is called
7030- * before a context switch and vTaskExitCritical() is called
7031- * after pxCurrentTCB changes. Therefore this should not be
7032- * used within vTaskSwitchContext(). */
7033- prvCheckForRunStateChange ();
7031+ portASSERT_IF_IN_ISR ();
7032+
7033+ if ( uxSchedulerSuspended == 0U )
7034+ {
7035+ /* The only time there would be a problem is if this is called
7036+ * before a context switch and vTaskExitCritical() is called
7037+ * after pxCurrentTCB changes. Therefore this should not be
7038+ * used within vTaskSwitchContext(). */
7039+ prvCheckForRunStateChange ();
7040+ }
70347041 }
70357042 }
7036- }
7037- else
7038- {
7039- mtCOVERAGE_TEST_MARKER ();
7043+ else
7044+ {
7045+ mtCOVERAGE_TEST_MARKER ();
7046+ }
70407047 }
70417048
70427049 traceRETURN_vTaskEnterCritical ();
@@ -7051,14 +7058,13 @@ static void prvResetNextTaskUnblockTime( void )
70517058 UBaseType_t vTaskEnterCriticalFromISR ( void )
70527059 {
70537060 UBaseType_t uxSavedInterruptStatus = 0 ;
7054- BaseType_t xCoreID ;
7061+ const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID () ;
70557062
70567063 traceENTER_vTaskEnterCriticalFromISR ();
70577064
70587065 if ( xSchedulerRunning != pdFALSE )
70597066 {
70607067 uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR ();
7061- xCoreID = ( BaseType_t ) portGET_CORE_ID ();
70627068
70637069 if ( portGET_CRITICAL_NESTING_COUNT ( xCoreID ) == 0U )
70647070 {
0 commit comments