From 8ede50cafd8279f0aff1da59d6d1b89a1fa5c2c3 Mon Sep 17 00:00:00 2001 From: Moral-Hao Date: Mon, 6 Nov 2023 17:50:32 +0800 Subject: [PATCH] Fix vTaskSwitchContext for smp. (#879) The function vTaskSwitchContext in smp has an parameter of core id, which means this function is not only used for the core who call it. Thus we should use the task running on the specific core id, instead of use the task running on the core who call this function. Co-authored-by: moral-hao <405197809@qq.com> --- tasks.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasks.c b/tasks.c index 2e1cce402..75dded41f 100644 --- a/tasks.c +++ b/tasks.c @@ -5142,7 +5142,7 @@ BaseType_t xTaskIncrementTick( void ) * are provided by the application, not the kernel. */ if( ulTotalRunTime[ xCoreID ] > ulTaskSwitchedInTime[ xCoreID ] ) { - pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime[ xCoreID ] - ulTaskSwitchedInTime[ xCoreID ] ); + pxCurrentTCBs[ xCoreID ]->ulRunTimeCounter += ( ulTotalRunTime[ xCoreID ] - ulTaskSwitchedInTime[ xCoreID ] ); } else { @@ -5159,7 +5159,7 @@ BaseType_t xTaskIncrementTick( void ) /* Before the currently running task is switched out, save its errno. */ #if ( configUSE_POSIX_ERRNO == 1 ) { - pxCurrentTCB->iTaskErrno = FreeRTOS_errno; + pxCurrentTCBs[ xCoreID ]->iTaskErrno = FreeRTOS_errno; } #endif @@ -5170,7 +5170,7 @@ BaseType_t xTaskIncrementTick( void ) /* After the new task is switched in, update the global errno. */ #if ( configUSE_POSIX_ERRNO == 1 ) { - FreeRTOS_errno = pxCurrentTCB->iTaskErrno; + FreeRTOS_errno = pxCurrentTCBs[ xCoreID ]->iTaskErrno; } #endif @@ -5178,7 +5178,7 @@ BaseType_t xTaskIncrementTick( void ) { /* Switch C-Runtime's TLS Block to point to the TLS * Block specific to this task. */ - configSET_TLS_BLOCK( pxCurrentTCB->xTLSBlock ); + configSET_TLS_BLOCK( pxCurrentTCBs[ xCoreID ]->xTLSBlock ); } #endif }