Skip to content

Commit

Permalink
Event Groups: snapshot xEventGroupSetBits returning value while in vT…
Browse files Browse the repository at this point in the history
…askSuspendAll (#1143)

Event Groups: snapshot xEventGroupSetBits returning value while in
vTaskSuspendAll. Fixes uxEventBits dereference after event group
deleted by higher priority thread.
  • Loading branch information
skotopes authored Sep 11, 2024
1 parent d806240 commit d3052f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
9 changes: 6 additions & 3 deletions event_groups.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@
ListItem_t * pxNext;
ListItem_t const * pxListEnd;
List_t const * pxList;
EventBits_t uxBitsToClear = 0, uxBitsWaitedFor, uxControlBits;
EventBits_t uxBitsToClear = 0, uxBitsWaitedFor, uxControlBits, uxReturnBits;
EventGroup_t * pxEventBits = xEventGroup;
BaseType_t xMatchFound = pdFALSE;

Expand Down Expand Up @@ -635,12 +635,15 @@
/* Clear any bits that matched when the eventCLEAR_EVENTS_ON_EXIT_BIT
* bit was set in the control word. */
pxEventBits->uxEventBits &= ~uxBitsToClear;

/* Snapshot resulting bits. */
uxReturnBits = pxEventBits->uxEventBits;
}
( void ) xTaskResumeAll();

traceRETURN_xEventGroupSetBits( pxEventBits->uxEventBits );
traceRETURN_xEventGroupSetBits( uxReturnBits );

return pxEventBits->uxEventBits;
return uxReturnBits;
}
/*-----------------------------------------------------------*/

Expand Down
13 changes: 5 additions & 8 deletions include/event_groups.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,11 @@ EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
* and bit 0 set uxBitsToSet to 0x09.
*
* @return The value of the event group at the time the call to
* xEventGroupSetBits() returns. There are two reasons why the returned value
* might have the bits specified by the uxBitsToSet parameter cleared. First,
* if setting a bit results in a task that was waiting for the bit leaving the
* blocked state then it is possible the bit will be cleared automatically
* (see the xClearBitOnExit parameter of xEventGroupWaitBits()). Second, any
* unblocked (or otherwise Ready state) task that has a priority above that of
* the task that called xEventGroupSetBits() will execute and may change the
* event group value before the call to xEventGroupSetBits() returns.
* xEventGroupSetBits() returns. Returned value might have the bits specified
* by the uxBitsToSet parameter cleared if setting a bit results in a task
* that was waiting for the bit leaving the blocked state then it is possible
* the bit will be cleared automatically (see the xClearBitOnExit parameter
* of xEventGroupWaitBits()).
*
* Example usage:
* @code{c}
Expand Down

0 comments on commit d3052f1

Please sign in to comment.