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.
Hi,
Thanks for finding, fixed in all active branches.
Giovanni