Skip to content

Commit e850728

Browse files
feat(freertos-smp): Add support for queue direct transfer buffer in task TCB
This commit adds support for queue direct transfer buffer being owned by the task's TCB. This inherently solves some design issues with the buffer being owned by the queue's object. On the flip side, this adds memory cost to the task's TCB.
1 parent 53a4490 commit e850728

File tree

4 files changed

+362
-189
lines changed

4 files changed

+362
-189
lines changed

include/FreeRTOS.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3291,6 +3291,11 @@ typedef struct xSTATIC_TCB
32913291
#if ( configUSE_POSIX_ERRNO == 1 )
32923292
int iDummy22;
32933293
#endif
3294+
3295+
#if ( configQUEUE_DIRECT_TRANSFER == 1 )
3296+
void * pvDummyDirectTransferBuffer;
3297+
BaseType_t xDummyDirectTransferPosition;
3298+
#endif
32943299
} StaticTask_t;
32953300

32963301
/*
@@ -3337,11 +3342,6 @@ typedef struct xSTATIC_QUEUE
33373342
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
33383343
portSPINLOCK_TYPE xDummySpinlock[ 2 ];
33393344
#endif /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
3340-
3341-
#if ( configQUEUE_DIRECT_TRANSFER == 1 )
3342-
void * pvDummyDirectTransferBuffer;
3343-
BaseType_t xDummyDirectTransferPosition;
3344-
#endif
33453345
} StaticQueue_t;
33463346
typedef StaticQueue_t StaticSemaphore_t;
33473347

include/task.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3758,6 +3758,68 @@ BaseType_t xTaskRemoveFromEventListFromISR( const List_t * const pxEventList ) P
37583758
void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem,
37593759
const TickType_t xItemValue ) PRIVILEGED_FUNCTION;
37603760

3761+
#if ( configQUEUE_DIRECT_TRANSFER == 1 )
3762+
3763+
/*
3764+
* THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
3765+
* INTERFACE FOR THE EXCLUSIVE USE OF THE QUEUE IMPLEMENTATION.
3766+
*
3767+
* Set the direct transfer buffer for the current task.
3768+
* Called when a task is about to block on a queue operation.
3769+
*/
3770+
void vTaskSetDirectTransferBuffer( void * pvBuffer,
3771+
BaseType_t xPosition,
3772+
TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
3773+
3774+
/*
3775+
* THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
3776+
* INTERFACE FOR THE EXCLUSIVE USE OF THE QUEUE IMPLEMENTATION.
3777+
*
3778+
* Clear the direct transfer buffer for a task.
3779+
* @param xTask The task handle
3780+
*/
3781+
void vTaskClearDirectTransferBuffer( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
3782+
3783+
/*
3784+
* THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
3785+
* INTERFACE FOR THE EXCLUSIVE USE OF THE QUEUE IMPLEMENTATION.
3786+
*
3787+
* Get the direct transfer buffer pointer from a task.
3788+
* @param xTask The task handle
3789+
* @return The buffer pointer, or NULL if not set
3790+
*
3791+
*/
3792+
void * pvTaskGetDirectTransferBuffer( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
3793+
3794+
/*
3795+
* THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
3796+
* INTERFACE FOR THE EXCLUSIVE USE OF THE QUEUE IMPLEMENTATION.
3797+
*
3798+
* Get the direct transfer position from a task.
3799+
* @param xTask The task handle
3800+
* @return The position, or -1 if not set
3801+
*
3802+
*/
3803+
BaseType_t xTaskGetDirectTransferPosition( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
3804+
3805+
/*
3806+
* THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
3807+
* INTERFACE FOR THE EXCLUSIVE USE OF THE QUEUE IMPLEMENTATION.
3808+
*
3809+
* Get the highest priority task from an event list if it has armed direct transfer.
3810+
* Checks only the head of the event list (O(1) operation) for deterministic behavior.
3811+
*
3812+
* If the highest priority task hasn't armed direct transfer (e.g., using xQueuePeek()),
3813+
* returns NULL and direct transfer is skipped for this operation. This is acceptable since
3814+
* direct transfer is an optimization, not a requirement.
3815+
*
3816+
* @param pxEventList The event list to check
3817+
* @return Task handle of highest priority task if it has armed transfer, or NULL otherwise
3818+
*/
3819+
TaskHandle_t xTaskGetHighestPriorityTaskWithDirectTransferArmed( const List_t * const pxEventList ) PRIVILEGED_FUNCTION;
3820+
3821+
#endif /* configQUEUE_DIRECT_TRANSFER */
3822+
37613823
/*
37623824
* THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
37633825
* INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS

0 commit comments

Comments
 (0)