From 0640b2e4863bfdf628406cc90e29200a9220e088 Mon Sep 17 00:00:00 2001 From: Moral-Hao Date: Tue, 7 Nov 2023 15:33:07 +0800 Subject: [PATCH] Distinguish waiting for notify status from suspend status (#865) * Fix prvTaskIsTaskSuspended. Just like eTaskGetState, distinguish waiting for notify from suspend. * Fix vTaskGetInfo. Just like eTaskGetState, distinguish block state (waiting on notification) from suspend state. * Add missing definition of variable x. * Fix formatting syntax. --------- Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com> Co-authored-by: Tony Josi --- tasks.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/tasks.c b/tasks.c index 75dded41f..5500bf435 100644 --- a/tasks.c +++ b/tasks.c @@ -3284,10 +3284,34 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, if( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxTCB->xEventListItem ) ) == pdFALSE ) { /* Is it in the suspended list because it is in the Suspended - * state, or because is is blocked with no timeout? */ + * state, or because it is blocked with no timeout? */ if( listIS_CONTAINED_WITHIN( NULL, &( pxTCB->xEventListItem ) ) != pdFALSE ) /*lint !e961. The cast is only redundant when NULL is used. */ { - xReturn = pdTRUE; + #if ( configUSE_TASK_NOTIFICATIONS == 1 ) + { + BaseType_t x; + + /* The task does not appear on the event list item of + * and of the RTOS objects, but could still be in the + * blocked state if it is waiting on its notification + * rather than waiting on an object. If not, is + * suspended. */ + xReturn = pdTRUE; + + for( x = ( BaseType_t ) 0; x < ( BaseType_t ) configTASK_NOTIFICATION_ARRAY_ENTRIES; x++ ) + { + if( pxTCB->ucNotifyState[ x ] == taskWAITING_NOTIFICATION ) + { + xReturn = pdFALSE; + break; + } + } + } + #else /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */ + { + xReturn = pdTRUE; + } + #endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */ } else { @@ -6131,6 +6155,24 @@ static void prvCheckTasksWaitingTermination( void ) { pxTaskStatus->eCurrentState = eBlocked; } + else + { + BaseType_t x; + + /* The task does not appear on the event list item of + * and of the RTOS objects, but could still be in the + * blocked state if it is waiting on its notification + * rather than waiting on an object. If not, is + * suspended. */ + for( x = ( BaseType_t ) 0; x < ( BaseType_t ) configTASK_NOTIFICATION_ARRAY_ENTRIES; x++ ) + { + if( pxTCB->ucNotifyState[ x ] == taskWAITING_NOTIFICATION ) + { + pxTaskStatus->eCurrentState = eBlocked; + break; + } + } + } } ( void ) xTaskResumeAll(); }