forked from espressif/esp-idf
refactor(freertos/idf): Move vTaskSetThreadLocalStoragePointerAndDelCallback()
This commit moves vTaskSetThreadLocalStoragePointerAndDelCallback() from `tasks.c`/`task.h` to `freertos_tasks_c_additions.h`/`idf_additions.h`.
This commit is contained in:
@@ -2024,7 +2024,6 @@ configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVIL
|
||||
BaseType_t xIndex,
|
||||
void * pvValue ) PRIVILEGED_FUNCTION;
|
||||
|
||||
|
||||
/**
|
||||
* Get local storage pointer specific to the given task.
|
||||
*
|
||||
@@ -2041,39 +2040,6 @@ configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVIL
|
||||
void * pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery,
|
||||
BaseType_t xIndex ) PRIVILEGED_FUNCTION;
|
||||
|
||||
#if ( configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS == 1 )
|
||||
|
||||
/**
|
||||
* Prototype of local storage pointer deletion callback.
|
||||
*/
|
||||
typedef void (*TlsDeleteCallbackFunction_t)( int, void * );
|
||||
|
||||
/**
|
||||
* Set local storage pointer and deletion callback.
|
||||
*
|
||||
* Each task contains an array of pointers that is dimensioned by the
|
||||
* configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h.
|
||||
* The kernel does not use the pointers itself, so the application writer
|
||||
* can use the pointers for any purpose they wish.
|
||||
*
|
||||
* Local storage pointers set for a task can reference dynamically
|
||||
* allocated resources. This function is similar to
|
||||
* vTaskSetThreadLocalStoragePointer, but provides a way to release
|
||||
* these resources when the task gets deleted. For each pointer,
|
||||
* a callback function can be set. This function will be called
|
||||
* when task is deleted, with the local storage pointer index
|
||||
* and value as arguments.
|
||||
*
|
||||
* @param xTaskToSet Task to set thread local storage pointer for
|
||||
* @param xIndex The index of the pointer to set, from 0 to
|
||||
* configNUM_THREAD_LOCAL_STORAGE_POINTERS - 1.
|
||||
* @param pvValue Pointer value to set.
|
||||
* @param pvDelCallback Function to call to dispose of the local
|
||||
* storage pointer when the task is deleted.
|
||||
*/
|
||||
void vTaskSetThreadLocalStoragePointerAndDelCallback( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue, TlsDeleteCallbackFunction_t pvDelCallback);
|
||||
#endif
|
||||
|
||||
#endif /* if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 ) */
|
||||
|
||||
#if ( configCHECK_FOR_STACK_OVERFLOW > 0 )
|
||||
|
@@ -4331,79 +4331,42 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
|
||||
|
||||
#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )
|
||||
|
||||
#if ( configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS == 1 )
|
||||
|
||||
void vTaskSetThreadLocalStoragePointerAndDelCallback( TaskHandle_t xTaskToSet,
|
||||
BaseType_t xIndex,
|
||||
void * pvValue,
|
||||
TlsDeleteCallbackFunction_t xDelCallback )
|
||||
void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet,
|
||||
BaseType_t xIndex,
|
||||
void * pvValue )
|
||||
{
|
||||
#if ( configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS == 1 )
|
||||
{
|
||||
/* TLSP Deletion Callbacks are enabled. Call the TLSPDC funciton
|
||||
* instead with a NULL callback. */
|
||||
vTaskSetThreadLocalStoragePointerAndDelCallback( xTaskToSet, xIndex, pvValue, NULL );
|
||||
}
|
||||
#else /* configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS == 1 */
|
||||
{
|
||||
TCB_t * pxTCB;
|
||||
|
||||
/* If TLSP deletion callbacks are enabled, then
|
||||
* configNUM_THREAD_LOCAL_STORAGE_POINTERS is doubled in size so
|
||||
* that the latter half of the pvThreadLocalStoragePointers stores
|
||||
* the deletion callbacks. */
|
||||
if( xIndex < ( configNUM_THREAD_LOCAL_STORAGE_POINTERS / 2 ) )
|
||||
{
|
||||
#if ( configNUM_CORES > 1 )
|
||||
#if ( configNUM_CORES > 1 )
|
||||
|
||||
/* For SMP, we need to take the kernel lock here as we
|
||||
* another core could also update this task's TLSP at the
|
||||
* same time. */
|
||||
taskENTER_CRITICAL( &xKernelLock );
|
||||
#endif /* ( configNUM_CORES > 1 ) */
|
||||
|
||||
pxTCB = prvGetTCBFromHandle( xTaskToSet );
|
||||
/* Store the TLSP by indexing the first half of the array */
|
||||
pxTCB->pvThreadLocalStoragePointers[ xIndex ] = pvValue;
|
||||
/* Store the TLSP deletion callback by indexing the second half
|
||||
* of the array. */
|
||||
pxTCB->pvThreadLocalStoragePointers[ ( xIndex + ( configNUM_THREAD_LOCAL_STORAGE_POINTERS / 2 ) ) ] = ( void * ) xDelCallback;
|
||||
|
||||
#if ( configNUM_CORES > 1 )
|
||||
/* Release the previously taken kernel lock. */
|
||||
taskEXIT_CRITICAL( &xKernelLock );
|
||||
#endif /* configNUM_CORES > 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet,
|
||||
BaseType_t xIndex,
|
||||
void * pvValue )
|
||||
{
|
||||
vTaskSetThreadLocalStoragePointerAndDelCallback( xTaskToSet, xIndex, pvValue, ( TlsDeleteCallbackFunction_t ) NULL );
|
||||
}
|
||||
|
||||
|
||||
#else /* if ( configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS == 1 ) */
|
||||
void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet,
|
||||
BaseType_t xIndex,
|
||||
void * pvValue )
|
||||
{
|
||||
TCB_t * pxTCB;
|
||||
/* For SMP, we need to take the kernel lock here as we
|
||||
* another core could also update this task's TLSP at the
|
||||
* same time. */
|
||||
taskENTER_CRITICAL( &xKernelLock );
|
||||
#endif /* ( configNUM_CORES > 1 ) */
|
||||
|
||||
if( xIndex < configNUM_THREAD_LOCAL_STORAGE_POINTERS )
|
||||
{
|
||||
#if ( configNUM_CORES > 1 )
|
||||
|
||||
/* For SMP, we need to take the kernel lock here as we
|
||||
* another core could also update this task's TLSP at the
|
||||
* same time. */
|
||||
taskENTER_CRITICAL( &xKernelLock );
|
||||
#endif /* ( configNUM_CORES > 1 ) */
|
||||
|
||||
pxTCB = prvGetTCBFromHandle( xTaskToSet );
|
||||
configASSERT( pxTCB != NULL );
|
||||
pxTCB->pvThreadLocalStoragePointers[ xIndex ] = pvValue;
|
||||
|
||||
#if ( configNUM_CORES > 1 )
|
||||
/* Release the previously taken kernel lock. */
|
||||
taskEXIT_CRITICAL( &xKernelLock );
|
||||
#endif /* configNUM_CORES > 1 */
|
||||
}
|
||||
|
||||
#if ( configNUM_CORES > 1 )
|
||||
/* Release the previously taken kernel lock. */
|
||||
taskEXIT_CRITICAL( &xKernelLock );
|
||||
#endif /* configNUM_CORES > 1 */
|
||||
}
|
||||
#endif /* configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS == 1 */
|
||||
#endif /* configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS == 1 */
|
||||
}
|
||||
|
||||
#endif /* configNUM_THREAD_LOCAL_STORAGE_POINTERS */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
@@ -21,7 +21,7 @@
|
||||
|
||||
/* ------------------------------------------------- Static Asserts ------------------------------------------------- */
|
||||
|
||||
/**
|
||||
/*
|
||||
* Both StaticTask_t and TCB_t structures are provided by FreeRTOS sources.
|
||||
* This is just an additional check of the consistency of these structures.
|
||||
*/
|
||||
@@ -555,26 +555,61 @@ uint8_t * pxTaskGetStackStart( TaskHandle_t xTask )
|
||||
|
||||
/* --------------------------------------------- TLSP Deletion Callbacks -------------------------------------------- */
|
||||
|
||||
#if ( CONFIG_FREERTOS_SMP && CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS )
|
||||
#if CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS
|
||||
|
||||
void vTaskSetThreadLocalStoragePointerAndDelCallback( TaskHandle_t xTaskToSet,
|
||||
BaseType_t xIndex,
|
||||
void * pvValue,
|
||||
TlsDeleteCallbackFunction_t pvDelCallback )
|
||||
{
|
||||
/* Verify that the offsets of pvThreadLocalStoragePointers and pvDummy15 match. */
|
||||
/* pvDummy15 is part of the StaticTask_t struct and is used to access the TLSPs */
|
||||
/* while deletion. */
|
||||
_Static_assert( offsetof( StaticTask_t, pvDummy15 ) == offsetof( TCB_t, pvThreadLocalStoragePointers ), "Offset of pvDummy15 must match the offset of pvThreadLocalStoragePointers" );
|
||||
/* If TLSP deletion callbacks are enabled, then configNUM_THREAD_LOCAL_STORAGE_POINTERS
|
||||
* is doubled in size so that the latter half of the pvThreadLocalStoragePointers
|
||||
* stores the deletion callbacks. */
|
||||
if( xIndex < ( configNUM_THREAD_LOCAL_STORAGE_POINTERS / 2 ) )
|
||||
{
|
||||
TCB_t * pxTCB;
|
||||
|
||||
/*Set the local storage pointer first */
|
||||
vTaskSetThreadLocalStoragePointer( xTaskToSet, xIndex, pvValue );
|
||||
#if ( configNUM_CORES > 1 )
|
||||
{
|
||||
/* For SMP, we need a critical section as another core could also
|
||||
* update this task's TLSP at the same time. */
|
||||
#if CONFIG_FREERTOS_SMP
|
||||
{
|
||||
taskENTER_CRITICAL();
|
||||
}
|
||||
#else /* CONFIG_FREERTOS_SMP */
|
||||
{
|
||||
taskENTER_CRITICAL( &xKernelLock );
|
||||
}
|
||||
#endif /* CONFIG_FREERTOS_SMP */
|
||||
}
|
||||
#endif /* configNUM_CORES > 1 */
|
||||
|
||||
/*Set the deletion callback at an offset of configNUM_THREAD_LOCAL_STORAGE_POINTERS/2 */
|
||||
vTaskSetThreadLocalStoragePointer( xTaskToSet, ( xIndex + ( configNUM_THREAD_LOCAL_STORAGE_POINTERS / 2 ) ), pvDelCallback );
|
||||
pxTCB = prvGetTCBFromHandle( xTaskToSet );
|
||||
/* Store the TLSP by indexing the first half of the array */
|
||||
pxTCB->pvThreadLocalStoragePointers[ xIndex ] = pvValue;
|
||||
|
||||
/* Store the TLSP deletion callback by indexing the second half
|
||||
* of the array. */
|
||||
pxTCB->pvThreadLocalStoragePointers[ ( xIndex + ( configNUM_THREAD_LOCAL_STORAGE_POINTERS / 2 ) ) ] = ( void * ) pvDelCallback;
|
||||
|
||||
#if ( configNUM_CORES > 1 )
|
||||
{
|
||||
#if CONFIG_FREERTOS_SMP
|
||||
{
|
||||
taskEXIT_CRITICAL();
|
||||
}
|
||||
#else /* CONFIG_FREERTOS_SMP */
|
||||
{
|
||||
taskEXIT_CRITICAL( &xKernelLock );
|
||||
}
|
||||
#endif /* CONFIG_FREERTOS_SMP */
|
||||
}
|
||||
#endif /* configNUM_CORES > 1 */
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_FREERTOS_SMP && CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS */
|
||||
#endif /* CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS */
|
||||
/*----------------------------------------------------------*/
|
||||
|
||||
/* ----------------------------------------------------- Newlib ----------------------------------------------------- */
|
||||
|
@@ -166,25 +166,18 @@ BaseType_t xTaskGetAffinity( TaskHandle_t xTask );
|
||||
*/
|
||||
uint8_t * pxTaskGetStackStart( TaskHandle_t xTask );
|
||||
|
||||
/* --------------------------------------------- TLSP Deletion Callbacks -----------------------------------------------
|
||||
* TLSP Deletion Callback API Additions
|
||||
*
|
||||
* Todo: Move IDF FreeRTOS TLSP Deletion Callback related additions to this header as well (see IDF-7201)
|
||||
* Todo: Add these SMP related additions to docs once they are combined with IDF FreeRTOS.
|
||||
* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* --------------------------------------------- TLSP Deletion Callbacks -------------------------------------------- */
|
||||
|
||||
#if ( CONFIG_FREERTOS_SMP && CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS )
|
||||
#if CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS
|
||||
|
||||
/**
|
||||
* Prototype of local storage pointer deletion callback.
|
||||
*/
|
||||
typedef void (* TlsDeleteCallbackFunction_t)( int,
|
||||
void * );
|
||||
#endif /* CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS */
|
||||
|
||||
#endif /* ( CONFIG_FREERTOS_SMP && CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS ) */
|
||||
|
||||
|
||||
#if ( CONFIG_FREERTOS_SMP && CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS )
|
||||
#if CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS
|
||||
|
||||
/**
|
||||
* Set local storage pointer and deletion callback.
|
||||
@@ -213,7 +206,7 @@ uint8_t * pxTaskGetStackStart( TaskHandle_t xTask );
|
||||
void * pvValue,
|
||||
TlsDeleteCallbackFunction_t pvDelCallback );
|
||||
|
||||
#endif /* ( CONFIG_FREERTOS_SMP && CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS ) */
|
||||
#endif /* CONFIG_FREERTOS_TLSP_DELETION_CALLBACKS */
|
||||
|
||||
/* -------------------------------------------- Creation With Memory Caps ----------------------------------------------
|
||||
* Helper functions to create various FreeRTOS objects (e.g., queues, semaphores) with specific memory capabilities
|
||||
|
@@ -146,8 +146,6 @@ entries:
|
||||
tasks:xTaskCheckForTimeOut (default)
|
||||
tasks:vTaskMissedYield (default)
|
||||
tasks:prvIdleTask (default)
|
||||
if FREERTOS_TLSP_DELETION_CALLBACKS = y:
|
||||
tasks:vTaskSetThreadLocalStoragePointerAndDelCallback (default)
|
||||
if FREERTOS_THREAD_LOCAL_STORAGE_POINTERS != 0:
|
||||
tasks:vTaskSetThreadLocalStoragePointer (default)
|
||||
tasks:pvTaskGetThreadLocalStoragePointer (default)
|
||||
|
Reference in New Issue
Block a user