Menu

#989 bug in chEvtBroadcastFlagsI

18.2.2
closed
None
RT
Medium
17.6.4
True
2019-02-07
2018-11-18
rushmash
No

Hi, there seems to be a minor bug in chEvtBroadcastFlagsI().

Consider the following simple case:

EventListener listener;
chEvtRegisterMaskWithFlags(&uart, &listener, UsartEvent, CHN_INPUT_AVAILABLE);

while (true)
{
    chEvtWaitAny(UsartEvent);

    // we designed this thread to be waken up only with UsartEvent on CHN_INPUT_AVAILABLE
    // this is the only one condition when this thread is woken up
    // so we can skip checking flags with getAndClearFlags here
    // but if we do that then chEvtBroadcastFlagsI() will wake it up for any other flags, e.g. CHN_TRANSMISSION_END
    // this is wrong!
    parse();
}

If we don't use getAndClearFlags() to clear flags then chEvtBroadcastFlagsI()
will wake up listener-thread for all broadcasted flags to which it's not even subscribed!

Proposed fix is:

diff --git a/rt/src/chevents.c b/rt/src/chevents.c
index 301e016..a5eece9 100644
--- a/rt/src/chevents.c
+++ b/rt/src/chevents.c
@@ -236,7 +236,7 @@ void chEvtBroadcastFlagsI(event_source_t *esp, eventflags_t flags) {
     /* When flags == 0 the thread will always be signaled because the
        source does not emit any flag.*/
     if ((flags == (eventflags_t)0) ||
-        ((elp->flags & elp->wflags) != (eventflags_t)0)) {
+        ((flags & elp->wflags) != (eventflags_t)0)) {
       chEvtSignalI(elp->listener, elp->events);
     }
     elp = elp->next;

Please check!
Thanks in advance.

Discussion

  • Giovanni Di Sirio

    • assigned_to: Giovanni Di Sirio
    • Severity: Low --> Medium
    • Affected Version: 18.2.1 --> 17.6.4
    • Fixed in Repository: False --> True
     
  • Giovanni Di Sirio

    Hi,

    Thanks for finding, fixed in all active branches.

    Giovanni

     
  • Giovanni Di Sirio

    • Status: open --> closed
     

Log in to post a comment.