@@ -7659,62 +7659,61 @@ TickType_t uxTaskResetEventItemValue( void )
7659
7659
7660
7660
configASSERT ( uxIndexToWaitOn < configTASK_NOTIFICATION_ARRAY_ENTRIES );
7661
7661
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 ) )
7665
7665
{
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 ();
7671
7669
{
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 ();
7674
7675
{
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 )
7679
7678
{
7679
+ /* Mark this task as waiting for a notification. */
7680
+ pxCurrentTCB -> ucNotifyState [ uxIndexToWaitOn ] = taskWAITING_NOTIFICATION ;
7681
+
7682
+ /* Arrange to wait for a notification. */
7680
7683
xShouldBlock = pdTRUE ;
7681
7684
}
7682
7685
else
7683
7686
{
7684
7687
mtCOVERAGE_TEST_MARKER ();
7685
7688
}
7686
7689
}
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
+ }
7687
7700
else
7688
7701
{
7689
7702
mtCOVERAGE_TEST_MARKER ();
7690
7703
}
7691
7704
}
7692
- taskEXIT_CRITICAL ();
7705
+ xAlreadyYielded = xTaskResumeAll ();
7693
7706
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 ) )
7698
7709
{
7699
- traceTASK_NOTIFY_TAKE_BLOCK ( uxIndexToWaitOn );
7700
- prvAddCurrentTaskToDelayedList ( xTicksToWait , pdTRUE );
7710
+ taskYIELD_WITHIN_API ();
7701
7711
}
7702
7712
else
7703
7713
{
7704
7714
mtCOVERAGE_TEST_MARKER ();
7705
7715
}
7706
7716
}
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
- }
7718
7717
7719
7718
taskENTER_CRITICAL ();
7720
7719
{
@@ -7763,66 +7762,65 @@ TickType_t uxTaskResetEventItemValue( void )
7763
7762
7764
7763
configASSERT ( uxIndexToWaitOn < configTASK_NOTIFICATION_ARRAY_ENTRIES );
7765
7764
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 ) )
7769
7768
{
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 ();
7774
7772
{
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 ();
7777
7777
{
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 ;
7782
7785
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 ;
7785
7788
7786
- if ( xTicksToWait > ( TickType_t ) 0 )
7787
- {
7789
+ /* Arrange to wait for a notification. */
7788
7790
xShouldBlock = pdTRUE ;
7789
7791
}
7790
7792
else
7791
7793
{
7792
7794
mtCOVERAGE_TEST_MARKER ();
7793
7795
}
7794
7796
}
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
+ }
7795
7807
else
7796
7808
{
7797
7809
mtCOVERAGE_TEST_MARKER ();
7798
7810
}
7799
7811
}
7800
- taskEXIT_CRITICAL ();
7812
+ xAlreadyYielded = xTaskResumeAll ();
7801
7813
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 ) )
7806
7816
{
7807
- traceTASK_NOTIFY_WAIT_BLOCK ( uxIndexToWaitOn );
7808
- prvAddCurrentTaskToDelayedList ( xTicksToWait , pdTRUE );
7817
+ taskYIELD_WITHIN_API ();
7809
7818
}
7810
7819
else
7811
7820
{
7812
7821
mtCOVERAGE_TEST_MARKER ();
7813
7822
}
7814
7823
}
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
- }
7826
7824
7827
7825
taskENTER_CRITICAL ();
7828
7826
{
0 commit comments