-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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. #625
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3137,8 +3137,8 @@ void vTaskPlaceOnEventList( List_t * const pxEventList, | |
{ | ||
configASSERT( pxEventList ); | ||
|
||
/* THIS FUNCTION MUST BE CALLED WITH EITHER INTERRUPTS DISABLED OR THE | ||
* SCHEDULER SUSPENDED AND THE QUEUE BEING ACCESSED LOCKED. */ | ||
/* 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. | ||
* This is placed in the list in priority order so the highest priority task | ||
|
@@ -4744,22 +4744,25 @@ TickType_t uxTaskResetEventItemValue( void ) | |
configASSERT( uxIndexToWait < configTASK_NOTIFICATION_ARRAY_ENTRIES ); | ||
|
||
taskENTER_CRITICAL(); | ||
|
||
/* Only block if the notification count is not already non-zero. */ | ||
if( pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] == 0UL ) | ||
{ | ||
/* Only block if the notification count is not already non-zero. */ | ||
if( pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] == 0UL ) | ||
/* Mark this task as waiting for a notification. */ | ||
pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskWAITING_NOTIFICATION; | ||
|
||
if( xTicksToWait > ( TickType_t ) 0 ) | ||
{ | ||
/* Mark this task as waiting for a notification. */ | ||
pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskWAITING_NOTIFICATION; | ||
traceTASK_NOTIFY_TAKE_BLOCK( uxIndexToWait ); | ||
|
||
if( xTicksToWait > ( TickType_t ) 0 ) | ||
{ | ||
prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE ); | ||
traceTASK_NOTIFY_TAKE_BLOCK( uxIndexToWait ); | ||
/* Suspend the scheduler before enabling interrupts. */ | ||
vTaskSuspendAll(); | ||
taskEXIT_CRITICAL(); | ||
Comment on lines
+4758
to
+4760
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strictly speaking, the API doesn't allow calling vTaskSuspendAll() from inside a critical section. It probably works, but it would be the only place it happens in the FreeRTOS codebase. The intent behind the larger construct being proposed here seems to be to avoid suspending/resuming the scheduler if possible, which in turn keeps |
||
|
||
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. */ | ||
if( xTaskResumeAll() == pdFALSE ) | ||
{ | ||
portYIELD_WITHIN_API(); | ||
} | ||
else | ||
|
@@ -4769,10 +4772,13 @@ TickType_t uxTaskResetEventItemValue( void ) | |
} | ||
else | ||
{ | ||
mtCOVERAGE_TEST_MARKER(); | ||
taskEXIT_CRITICAL(); | ||
} | ||
} | ||
taskEXIT_CRITICAL(); | ||
else | ||
{ | ||
taskEXIT_CRITICAL(); | ||
} | ||
|
||
taskENTER_CRITICAL(); | ||
{ | ||
|
@@ -4818,27 +4824,30 @@ TickType_t uxTaskResetEventItemValue( void ) | |
configASSERT( uxIndexToWait < configTASK_NOTIFICATION_ARRAY_ENTRIES ); | ||
|
||
taskENTER_CRITICAL(); | ||
|
||
/* Only block if a notification is not already pending. */ | ||
if( pxCurrentTCB->ucNotifyState[ uxIndexToWait ] != taskNOTIFICATION_RECEIVED ) | ||
{ | ||
/* Only block if a notification is not already pending. */ | ||
if( pxCurrentTCB->ucNotifyState[ uxIndexToWait ] != 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[ uxIndexToWait ] &= ~ulBitsToClearOnEntry; | ||
|
||
/* Mark this task as waiting for a notification. */ | ||
pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = 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[ uxIndexToWait ] &= ~ulBitsToClearOnEntry; | ||
traceTASK_NOTIFY_WAIT_BLOCK( uxIndexToWait ); | ||
|
||
/* Mark this task as waiting for a notification. */ | ||
pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskWAITING_NOTIFICATION; | ||
/* Suspend the scheduler before enabling interrupts. */ | ||
vTaskSuspendAll(); | ||
taskEXIT_CRITICAL(); | ||
|
||
if( xTicksToWait > ( TickType_t ) 0 ) | ||
{ | ||
prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE ); | ||
traceTASK_NOTIFY_WAIT_BLOCK( uxIndexToWait ); | ||
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. */ | ||
if( xTaskResumeAll() == pdFALSE ) | ||
{ | ||
portYIELD_WITHIN_API(); | ||
} | ||
else | ||
|
@@ -4848,10 +4857,13 @@ TickType_t uxTaskResetEventItemValue( void ) | |
} | ||
else | ||
{ | ||
mtCOVERAGE_TEST_MARKER(); | ||
taskEXIT_CRITICAL(); | ||
} | ||
} | ||
taskEXIT_CRITICAL(); | ||
else | ||
{ | ||
taskEXIT_CRITICAL(); | ||
} | ||
|
||
taskENTER_CRITICAL(); | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this comment changed? The original "Interrupts disabled" should probably be "inside a critical section", but I think it's still valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it because this function calls vListInsert(), which shouldn't be called while interrupts are disabled as far as I am aware. I noted this comment in my original issue. But I can change it back if you think this is not correct.