Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix xTaskNotifyWait & ulTaskNotifyTake determinism. #833

Merged
merged 6 commits into from
Oct 17, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 72 additions & 35 deletions tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5127,7 +5127,7 @@ void vTaskPlaceOnEventList( List_t * const pxEventList,

configASSERT( pxEventList );

/* THIS FUNCTION MUST BE CALLED WITH EITHER INTERRUPTS DISABLED OR THE
/* THIS FUNCTION MUST BE CALLED WITH THE
* SCHEDULER SUSPENDED AND THE QUEUE BEING ACCESSED LOCKED. */

/* Place the event list item of the TCB in the appropriate event list.
Expand Down Expand Up @@ -7415,23 +7415,39 @@ TickType_t uxTaskResetEventItemValue( void )
configASSERT( uxIndexToWaitOn < configTASK_NOTIFICATION_ARRAY_ENTRIES );

taskENTER_CRITICAL();

/* Only block if the notification count is not already non-zero. */
if( pxCurrentTCB->ulNotifiedValue[ uxIndexToWaitOn ] == 0UL )
{
/* Only block if the notification count is not already non-zero. */
if( pxCurrentTCB->ulNotifiedValue[ uxIndexToWaitOn ] == 0UL )
/* Mark this task as waiting for a notification. */
pxCurrentTCB->ucNotifyState[ uxIndexToWaitOn ] = taskWAITING_NOTIFICATION;

if( xTicksToWait > ( TickType_t ) 0 )
{
/* Mark this task as waiting for a notification. */
pxCurrentTCB->ucNotifyState[ uxIndexToWaitOn ] = taskWAITING_NOTIFICATION;
prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE );
kar-rahul-aws marked this conversation as resolved.
Show resolved Hide resolved
traceTASK_NOTIFY_TAKE_BLOCK( uxIndexToWaitOn );

if( xTicksToWait > ( TickType_t ) 0 )
{
prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE );
traceTASK_NOTIFY_TAKE_BLOCK( uxIndexToWaitOn );
/* Suspend the scheduler before enabling interrupts. */
vTaskSuspendAll();
taskEXIT_CRITICAL();

prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE );

/* All ports are written to allow a yield in a critical
* section (some will yield immediately, others wait until the
* critical section exits) - but it is not something that
* application code should ever do. */
taskYIELD_WITHIN_API();
/* All ports are written to allow a yield in a critical
* section (some will yield immediately, others wait until the
* critical section exits) - but it is not something that
* application code should ever do. */
if( xTaskResumeAll() == pdFALSE )
{
#if ( configNUMBER_OF_CORES == 1 )
{
portYIELD_WITHIN_API();
}
#else
{
vTaskYieldWithinAPI();
}
#endif
}
else
{
Expand All @@ -7440,10 +7456,13 @@ TickType_t uxTaskResetEventItemValue( void )
}
else
{
mtCOVERAGE_TEST_MARKER();
taskEXIT_CRITICAL();
}
}
taskEXIT_CRITICAL();
else
{
taskEXIT_CRITICAL();
}

taskENTER_CRITICAL();
{
Expand Down Expand Up @@ -7493,28 +7512,43 @@ TickType_t uxTaskResetEventItemValue( void )
configASSERT( uxIndexToWaitOn < configTASK_NOTIFICATION_ARRAY_ENTRIES );

taskENTER_CRITICAL();

/* Only block if a notification is not already pending. */
if( pxCurrentTCB->ucNotifyState[ uxIndexToWaitOn ] != taskNOTIFICATION_RECEIVED )
{
/* Only block if a notification is not already pending. */
if( pxCurrentTCB->ucNotifyState[ uxIndexToWaitOn ] != taskNOTIFICATION_RECEIVED )
/* Clear bits in the task's notification value as bits may get
* set by the notifying task or interrupt. This can be used to
* clear the value to zero. */
pxCurrentTCB->ulNotifiedValue[ uxIndexToWaitOn ] &= ~ulBitsToClearOnEntry;

/* Mark this task as waiting for a notification. */
pxCurrentTCB->ucNotifyState[ uxIndexToWaitOn ] = taskWAITING_NOTIFICATION;

if( xTicksToWait > ( TickType_t ) 0 )
{
/* Clear bits in the task's notification value as bits may get
* set by the notifying task or interrupt. This can be used to
* clear the value to zero. */
pxCurrentTCB->ulNotifiedValue[ uxIndexToWaitOn ] &= ~ulBitsToClearOnEntry;
traceTASK_NOTIFY_WAIT_BLOCK( uxIndexToWaitOn );

/* Mark this task as waiting for a notification. */
pxCurrentTCB->ucNotifyState[ uxIndexToWaitOn ] = taskWAITING_NOTIFICATION;
/* Suspend the scheduler before enabling interrupts. */
vTaskSuspendAll();
taskEXIT_CRITICAL();

if( xTicksToWait > ( TickType_t ) 0 )
{
prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE );
traceTASK_NOTIFY_WAIT_BLOCK( uxIndexToWaitOn );
prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE );

/* All ports are written to allow a yield in a critical
* section (some will yield immediately, others wait until the
* critical section exits) - but it is not something that
* application code should ever do. */
taskYIELD_WITHIN_API();
/* All ports are written to allow a yield in a critical
* section (some will yield immediately, others wait until the
* critical section exits) - but it is not something that
* application code should ever do. */
if( xTaskResumeAll() == pdFALSE )
{
#if ( configNUMBER_OF_CORES == 1 )
{
portYIELD_WITHIN_API();
}
#else
{
vTaskYieldWithinAPI();
}
#endif
}
else
{
Expand All @@ -7523,10 +7557,13 @@ TickType_t uxTaskResetEventItemValue( void )
}
else
{
mtCOVERAGE_TEST_MARKER();
taskEXIT_CRITICAL();
}
}
taskEXIT_CRITICAL();
else
{
taskEXIT_CRITICAL();
}

taskENTER_CRITICAL();
{
Expand Down
Loading