| 3793 | /*-----------------------------------------------------------*/ |
| 3794 | |
| 3795 | void vTaskSwitchContext( BaseType_t xCoreID ) |
| 3796 | { |
| 3797 | /* Acquire both locks: |
| 3798 | * - The ISR lock protects the ready list from simultaneous access by |
| 3799 | * both other ISRs and tasks. |
| 3800 | * - We also take the task lock to pause here in case another core has |
| 3801 | * suspended the scheduler. We don't want to simply set xYieldPending |
| 3802 | * and move on if another core suspended the scheduler. We should only |
| 3803 | * do that if the current core has suspended the scheduler. */ |
| 3804 | |
| 3805 | portGET_TASK_LOCK(); /* Must always acquire the task lock first */ |
| 3806 | portGET_ISR_LOCK(); |
| 3807 | { |
| 3808 | /* vTaskSwitchContext() must never be called from within a critical section. |
| 3809 | * This is not necessarily true for vanilla FreeRTOS, but it is for this SMP port. */ |
| 3810 | configASSERT( pxCurrentTCB->uxCriticalNesting == 0 ); |
| 3811 | |
| 3812 | if( uxSchedulerSuspended != ( UBaseType_t ) pdFALSE ) |
| 3813 | { |
| 3814 | /* The scheduler is currently suspended - do not allow a context |
| 3815 | * switch. */ |
| 3816 | xYieldPendings[ xCoreID ] = pdTRUE; |
| 3817 | } |
| 3818 | else |
| 3819 | { |
| 3820 | xYieldPendings[ xCoreID ] = pdFALSE; |
| 3821 | traceTASK_SWITCHED_OUT(); |
| 3822 | |
| 3823 | #if ( configGENERATE_RUN_TIME_STATS == 1 ) |
| 3824 | { |
| 3825 | #ifdef portALT_GET_RUN_TIME_COUNTER_VALUE |
| 3826 | portALT_GET_RUN_TIME_COUNTER_VALUE( ulTotalRunTime ); |
| 3827 | #else |
| 3828 | ulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE(); |
| 3829 | #endif |
| 3830 | |
| 3831 | /* Add the amount of time the task has been running to the |
| 3832 | * accumulated time so far. The time the task started running was |
| 3833 | * stored in ulTaskSwitchedInTime. Note that there is no overflow |
| 3834 | * protection here so count values are only valid until the timer |
| 3835 | * overflows. The guard against negative values is to protect |
| 3836 | * against suspect run time stat counter implementations - which |
| 3837 | * are provided by the application, not the kernel. */ |
| 3838 | if( ulTotalRunTime > ulTaskSwitchedInTime ) |
| 3839 | { |
| 3840 | pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime ); |
| 3841 | } |
| 3842 | else |
| 3843 | { |
| 3844 | mtCOVERAGE_TEST_MARKER(); |
| 3845 | } |
| 3846 | |
| 3847 | ulTaskSwitchedInTime = ulTotalRunTime; |
| 3848 | } |
| 3849 | #endif /* configGENERATE_RUN_TIME_STATS */ |
| 3850 | |
| 3851 | /* Check for stack overflow, if configured. */ |
| 3852 | taskCHECK_FOR_STACK_OVERFLOW(); |
no test coverage detected