From 2c0cea641a3fb9d4e1f9c632027220370f5fb498 Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Fri, 10 Nov 2023 09:23:51 +0100 Subject: [PATCH] fix(freertos/idf): Define configLIST_VOLATILE for list elements It was noticed that when high level compiler optimizations are enabled, the compiler optimizes some list manupulation code. This commit enables the configLIST_VOLATILE for list elements to prevent the compiler from optimizing out essential kernel code. --- components/freertos/FreeRTOS-Kernel/tasks.c | 3 +-- components/freertos/config/include/freertos/FreeRTOSConfig.h | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/components/freertos/FreeRTOS-Kernel/tasks.c b/components/freertos/FreeRTOS-Kernel/tasks.c index d793e15656..26312e3100 100644 --- a/components/freertos/FreeRTOS-Kernel/tasks.c +++ b/components/freertos/FreeRTOS-Kernel/tasks.c @@ -2636,8 +2636,7 @@ BaseType_t xTaskResumeAll( void ) * appropriate ready list. */ while( listLIST_IS_EMPTY( &xPendingReadyList[ xCurCoreID ] ) == pdFALSE ) { - /* Note: Add volatile cast (IDF-8361) */ - pxTCB = listGET_OWNER_OF_HEAD_ENTRY( ( volatile List_t * ) ( &xPendingReadyList[ xCurCoreID ] ) ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ + pxTCB = listGET_OWNER_OF_HEAD_ENTRY( ( &xPendingReadyList[ xCurCoreID ] ) ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ listREMOVE_ITEM( &( pxTCB->xEventListItem ) ); portMEMORY_BARRIER(); listREMOVE_ITEM( &( pxTCB->xStateListItem ) ); diff --git a/components/freertos/config/include/freertos/FreeRTOSConfig.h b/components/freertos/config/include/freertos/FreeRTOSConfig.h index 623272fbc3..2d43bb0bd1 100644 --- a/components/freertos/config/include/freertos/FreeRTOSConfig.h +++ b/components/freertos/config/include/freertos/FreeRTOSConfig.h @@ -178,6 +178,10 @@ #define configTIMER_TASK_STACK_DEPTH CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH #define configTIMER_SERVICE_TASK_NAME CONFIG_FREERTOS_TIMER_SERVICE_TASK_NAME +/* ------------------------ List --------------------------- */ + +#define configLIST_VOLATILE volatile /* We define List elements as volatile to prevent the compiler from optimizing out essential code */ + /* -------------------- API Includes ----------------------- */ #if CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY