refactor(freertos/idf): Add critical section requirements to function description

This commit adds a note regarding the critical section calling requires of some
internal functions.
This commit is contained in:
Darian Leung 2024-05-14 23:01:50 +08:00
parent 7c38b262fb
commit 89c22c63e6
No known key found for this signature in database
GPG Key ID: 8AC9127B487AA4EF

View File

@ -141,6 +141,11 @@
* - If a yield is required on the current core, this macro return pdTRUE * - If a yield is required on the current core, this macro return pdTRUE
* - if a yield is required on the other core, this macro will internally * - if a yield is required on the other core, this macro will internally
* trigger it. * trigger it.
*
* - In SMP, these macros must be called from a critical section (where the
* kernel locks are taken).
* - In single-core, these macros must be called from a critical section or when
* the scheduler is suspended.
*/ */
#if ( configNUMBER_OF_CORES > 1 ) #if ( configNUMBER_OF_CORES > 1 )
#define taskIS_YIELD_REQUIRED( pxTCB, xYieldEqualPriority ) prvIsYieldRequiredSMP( ( pxTCB ), ( pxTCB )->uxPriority, xYieldEqualPriority ) #define taskIS_YIELD_REQUIRED( pxTCB, xYieldEqualPriority ) prvIsYieldRequiredSMP( ( pxTCB ), ( pxTCB )->uxPriority, xYieldEqualPriority )
@ -177,7 +182,12 @@
#endif /* configNUMBER_OF_CORES > 1 */ #endif /* configNUMBER_OF_CORES > 1 */
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Macros to check if a particular task is a currently running. */ /* Macros to check if a particular task is a currently running.
*
* - In SMP, these macros must be called from a critical section (where the
* kernel lock is taken).
* - In single-core, these macros must be called from a critical section or when
* the scheduler is suspended */
#if ( configNUMBER_OF_CORES > 1 ) #if ( configNUMBER_OF_CORES > 1 )
#define taskIS_CURRENTLY_RUNNING( pxTCB ) ( ( ( ( pxTCB ) == pxCurrentTCBs[ 0 ] ) || ( ( pxTCB ) == pxCurrentTCBs[ 1 ] ) ) ? pdTRUE : pdFALSE ) #define taskIS_CURRENTLY_RUNNING( pxTCB ) ( ( ( ( pxTCB ) == pxCurrentTCBs[ 0 ] ) || ( ( pxTCB ) == pxCurrentTCBs[ 1 ] ) ) ? pdTRUE : pdFALSE )
#define taskIS_CURRENTLY_RUNNING_ON_CORE( pxTCB, xCoreID ) ( ( ( pxTCB ) == pxCurrentTCBs[ ( xCoreID ) ] ) ? pdTRUE : pdFALSE ) #define taskIS_CURRENTLY_RUNNING_ON_CORE( pxTCB, xCoreID ) ( ( ( pxTCB ) == pxCurrentTCBs[ ( xCoreID ) ] ) ? pdTRUE : pdFALSE )
@ -193,7 +203,12 @@
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Macro to check if a particular task can currently be scheduled (i.e., is /* Macro to check if a particular task can currently be scheduled (i.e., is
* the scheduler suspended). */ * the scheduler suspended).
*
* - In SMP, these macros must be called from a critical section (where the
* kernel lock is taken).
* - In single-core, these macros must be called from a critical section or when
* the scheduler is suspended */
#if ( configNUMBER_OF_CORES > 1 ) #if ( configNUMBER_OF_CORES > 1 )
#define taskCAN_BE_SCHEDULED( pxTCB ) prvCheckTaskCanBeScheduledSMP( pxTCB ) #define taskCAN_BE_SCHEDULED( pxTCB ) prvCheckTaskCanBeScheduledSMP( pxTCB )
#else #else
@ -569,6 +584,9 @@ static BaseType_t prvCreateIdleTasks( void );
* Exit: * Exit:
* - Returns pdTRUE if the current core requires yielding * - Returns pdTRUE if the current core requires yielding
* - The other core will be triggered to yield if required * - The other core will be triggered to yield if required
*
* @note This function must be called from a critical section where the kernel
* lock is taken).
*/ */
#if ( configNUMBER_OF_CORES > 1 ) #if ( configNUMBER_OF_CORES > 1 )
@ -589,6 +607,9 @@ static BaseType_t prvCreateIdleTasks( void );
* - If a task is unpinned, check the scheduler suspension state on both cores. * - If a task is unpinned, check the scheduler suspension state on both cores.
* The task can be scheduled if the scheduler is not suspended on either of * The task can be scheduled if the scheduler is not suspended on either of
* the cores. * the cores.
*
* @note This function must be called from a critical section (where the kernel
* lock is taken).
*/ */
#if ( configNUMBER_OF_CORES > 1 ) #if ( configNUMBER_OF_CORES > 1 )
@ -772,6 +793,9 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
UBaseType_t uxTaskPriority, UBaseType_t uxTaskPriority,
BaseType_t xYieldEqualPriority ) BaseType_t xYieldEqualPriority )
{ {
/* This function must be called from a critical section (where the kernel
* lock is taken). */
configASSERT( uxTaskPriority < configMAX_PRIORITIES ); configASSERT( uxTaskPriority < configMAX_PRIORITIES );
/* Save core ID as we can no longer be preempted. */ /* Save core ID as we can no longer be preempted. */
@ -825,6 +849,9 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
static BaseType_t prvCheckTaskCanBeScheduledSMP( TCB_t * pxTCB ) static BaseType_t prvCheckTaskCanBeScheduledSMP( TCB_t * pxTCB )
{ {
/* This function must be called from a critical section (where the kernel
* lock is taken). */
BaseType_t xReturn; BaseType_t xReturn;
if( pxTCB->xCoreID == tskNO_AFFINITY ) if( pxTCB->xCoreID == tskNO_AFFINITY )