Skip to content

Commit c90dce9

Browse files
authored
Merge branch 'main' into heap_5
2 parents 39b5545 + 8f7f451 commit c90dce9

File tree

1 file changed

+65
-67
lines changed

1 file changed

+65
-67
lines changed

tasks.c

Lines changed: 65 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7659,62 +7659,61 @@ TickType_t uxTaskResetEventItemValue( void )
76597659

76607660
configASSERT( uxIndexToWaitOn < configTASK_NOTIFICATION_ARRAY_ENTRIES );
76617661

7662-
/* We suspend the scheduler here as prvAddCurrentTaskToDelayedList is a
7663-
* non-deterministic operation. */
7664-
vTaskSuspendAll();
7662+
/* If the notification count is zero, and if we are willing to wait for a
7663+
* notification, then block the task and wait. */
7664+
if( ( pxCurrentTCB->ulNotifiedValue[ uxIndexToWaitOn ] == 0U ) && ( xTicksToWait > ( TickType_t ) 0 ) )
76657665
{
7666-
/* We MUST enter a critical section to atomically check if a notification
7667-
* has occurred and set the flag to indicate that we are waiting for
7668-
* a notification. If we do not do so, a notification sent from an ISR
7669-
* will get lost. */
7670-
taskENTER_CRITICAL();
7666+
/* We suspend the scheduler here as prvAddCurrentTaskToDelayedList is a
7667+
* non-deterministic operation. */
7668+
vTaskSuspendAll();
76717669
{
7672-
/* Only block if the notification count is not already non-zero. */
7673-
if( pxCurrentTCB->ulNotifiedValue[ uxIndexToWaitOn ] == 0U )
7670+
/* We MUST enter a critical section to atomically check if a notification
7671+
* has occurred and set the flag to indicate that we are waiting for
7672+
* a notification. If we do not do so, a notification sent from an ISR
7673+
* will get lost. */
7674+
taskENTER_CRITICAL();
76747675
{
7675-
/* Mark this task as waiting for a notification. */
7676-
pxCurrentTCB->ucNotifyState[ uxIndexToWaitOn ] = taskWAITING_NOTIFICATION;
7677-
7678-
if( xTicksToWait > ( TickType_t ) 0 )
7676+
/* Only block if the notification count is not already non-zero. */
7677+
if( pxCurrentTCB->ulNotifiedValue[ uxIndexToWaitOn ] == 0U )
76797678
{
7679+
/* Mark this task as waiting for a notification. */
7680+
pxCurrentTCB->ucNotifyState[ uxIndexToWaitOn ] = taskWAITING_NOTIFICATION;
7681+
7682+
/* Arrange to wait for a notification. */
76807683
xShouldBlock = pdTRUE;
76817684
}
76827685
else
76837686
{
76847687
mtCOVERAGE_TEST_MARKER();
76857688
}
76867689
}
7690+
taskEXIT_CRITICAL();
7691+
7692+
/* We are now out of the critical section but the scheduler is still
7693+
* suspended, so we are safe to do non-deterministic operations such
7694+
* as prvAddCurrentTaskToDelayedList. */
7695+
if( xShouldBlock == pdTRUE )
7696+
{
7697+
traceTASK_NOTIFY_TAKE_BLOCK( uxIndexToWaitOn );
7698+
prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE );
7699+
}
76877700
else
76887701
{
76897702
mtCOVERAGE_TEST_MARKER();
76907703
}
76917704
}
7692-
taskEXIT_CRITICAL();
7705+
xAlreadyYielded = xTaskResumeAll();
76937706

7694-
/* We are now out of the critical section but the scheduler is still
7695-
* suspended, so we are safe to do non-deterministic operations such
7696-
* as prvAddCurrentTaskToDelayedList. */
7697-
if( xShouldBlock == pdTRUE )
7707+
/* Force a reschedule if xTaskResumeAll has not already done so. */
7708+
if( ( xShouldBlock == pdTRUE ) && ( xAlreadyYielded == pdFALSE ) )
76987709
{
7699-
traceTASK_NOTIFY_TAKE_BLOCK( uxIndexToWaitOn );
7700-
prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE );
7710+
taskYIELD_WITHIN_API();
77017711
}
77027712
else
77037713
{
77047714
mtCOVERAGE_TEST_MARKER();
77057715
}
77067716
}
7707-
xAlreadyYielded = xTaskResumeAll();
7708-
7709-
/* Force a reschedule if xTaskResumeAll has not already done so. */
7710-
if( ( xShouldBlock == pdTRUE ) && ( xAlreadyYielded == pdFALSE ) )
7711-
{
7712-
taskYIELD_WITHIN_API();
7713-
}
7714-
else
7715-
{
7716-
mtCOVERAGE_TEST_MARKER();
7717-
}
77187717

77197718
taskENTER_CRITICAL();
77207719
{
@@ -7763,66 +7762,65 @@ TickType_t uxTaskResetEventItemValue( void )
77637762

77647763
configASSERT( uxIndexToWaitOn < configTASK_NOTIFICATION_ARRAY_ENTRIES );
77657764

7766-
/* We suspend the scheduler here as prvAddCurrentTaskToDelayedList is a
7767-
* non-deterministic operation. */
7768-
vTaskSuspendAll();
7765+
/* If the task hasn't received a notification, and if we are willing to wait
7766+
* for it, then block the task and wait. */
7767+
if( ( pxCurrentTCB->ucNotifyState[ uxIndexToWaitOn ] != taskNOTIFICATION_RECEIVED ) && ( xTicksToWait > ( TickType_t ) 0 ) )
77697768
{
7770-
/* We MUST enter a critical section to atomically check and update the
7771-
* task notification value. If we do not do so, a notification from
7772-
* an ISR will get lost. */
7773-
taskENTER_CRITICAL();
7769+
/* We suspend the scheduler here as prvAddCurrentTaskToDelayedList is a
7770+
* non-deterministic operation. */
7771+
vTaskSuspendAll();
77747772
{
7775-
/* Only block if a notification is not already pending. */
7776-
if( pxCurrentTCB->ucNotifyState[ uxIndexToWaitOn ] != taskNOTIFICATION_RECEIVED )
7773+
/* We MUST enter a critical section to atomically check and update the
7774+
* task notification value. If we do not do so, a notification from
7775+
* an ISR will get lost. */
7776+
taskENTER_CRITICAL();
77777777
{
7778-
/* Clear bits in the task's notification value as bits may get
7779-
* set by the notifying task or interrupt. This can be used
7780-
* to clear the value to zero. */
7781-
pxCurrentTCB->ulNotifiedValue[ uxIndexToWaitOn ] &= ~ulBitsToClearOnEntry;
7778+
/* Only block if a notification is not already pending. */
7779+
if( pxCurrentTCB->ucNotifyState[ uxIndexToWaitOn ] != taskNOTIFICATION_RECEIVED )
7780+
{
7781+
/* Clear bits in the task's notification value as bits may get
7782+
* set by the notifying task or interrupt. This can be used
7783+
* to clear the value to zero. */
7784+
pxCurrentTCB->ulNotifiedValue[ uxIndexToWaitOn ] &= ~ulBitsToClearOnEntry;
77827785

7783-
/* Mark this task as waiting for a notification. */
7784-
pxCurrentTCB->ucNotifyState[ uxIndexToWaitOn ] = taskWAITING_NOTIFICATION;
7786+
/* Mark this task as waiting for a notification. */
7787+
pxCurrentTCB->ucNotifyState[ uxIndexToWaitOn ] = taskWAITING_NOTIFICATION;
77857788

7786-
if( xTicksToWait > ( TickType_t ) 0 )
7787-
{
7789+
/* Arrange to wait for a notification. */
77887790
xShouldBlock = pdTRUE;
77897791
}
77907792
else
77917793
{
77927794
mtCOVERAGE_TEST_MARKER();
77937795
}
77947796
}
7797+
taskEXIT_CRITICAL();
7798+
7799+
/* We are now out of the critical section but the scheduler is still
7800+
* suspended, so we are safe to do non-deterministic operations such
7801+
* as prvAddCurrentTaskToDelayedList. */
7802+
if( xShouldBlock == pdTRUE )
7803+
{
7804+
traceTASK_NOTIFY_WAIT_BLOCK( uxIndexToWaitOn );
7805+
prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE );
7806+
}
77957807
else
77967808
{
77977809
mtCOVERAGE_TEST_MARKER();
77987810
}
77997811
}
7800-
taskEXIT_CRITICAL();
7812+
xAlreadyYielded = xTaskResumeAll();
78017813

7802-
/* We are now out of the critical section but the scheduler is still
7803-
* suspended, so we are safe to do non-deterministic operations such
7804-
* as prvAddCurrentTaskToDelayedList. */
7805-
if( xShouldBlock == pdTRUE )
7814+
/* Force a reschedule if xTaskResumeAll has not already done so. */
7815+
if( ( xShouldBlock == pdTRUE ) && ( xAlreadyYielded == pdFALSE ) )
78067816
{
7807-
traceTASK_NOTIFY_WAIT_BLOCK( uxIndexToWaitOn );
7808-
prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE );
7817+
taskYIELD_WITHIN_API();
78097818
}
78107819
else
78117820
{
78127821
mtCOVERAGE_TEST_MARKER();
78137822
}
78147823
}
7815-
xAlreadyYielded = xTaskResumeAll();
7816-
7817-
/* Force a reschedule if xTaskResumeAll has not already done so. */
7818-
if( ( xShouldBlock == pdTRUE ) && ( xAlreadyYielded == pdFALSE ) )
7819-
{
7820-
taskYIELD_WITHIN_API();
7821-
}
7822-
else
7823-
{
7824-
mtCOVERAGE_TEST_MARKER();
7825-
}
78267824

78277825
taskENTER_CRITICAL();
78287826
{

0 commit comments

Comments
 (0)