Page 1 of 1

Is chEvtBroadcastFlagsI() correct ?

Posted: Fri Jun 13, 2014 4:32 am
by kunilkuda
Hello,

I'm using ChibiOS 2.6.4. I found something that looks like a bug in chEvtBroadcastFlagsI():

Code: Select all

void chEvtBroadcastFlagsI(EventSource *esp, flagsmask_t flags) {
  EventListener *elp;

  chDbgCheckClassI();
  chDbgCheck(esp != NULL, "chEvtBroadcastMaskI");

  elp = esp->es_next;
  while (elp != (EventListener *)esp) {
    elp->el_flags |= flags;
    chEvtSignalI(elp->el_listener, elp->el_mask); // Why do we send event mask to listeners ?
    elp = elp->el_next;
  }
}


This will force all listeners on the event to wake up, regardless whether they are waiting the correct flag or not. Based on the docs, I believe the chEvtBroadcastFlagsI() should send the flag to each of the event listeners:

Code: Select all

  while (elp != (EventListener *)esp) {
    elp->el_flags |= flags;
    chEvtSignalI(elp->el_listener, flags); // Send the flag(s) to listeners
    elp = elp->el_next;
  }


Cheers,
-Daniel

Re: Is chEvtBroadcastFlagsI() correct ?

Posted: Fri Jun 13, 2014 8:46 am
by Giovanni
Hi,

Those are two different kind of flags, in the EventListener there is the OR of the flags that the EventSource broadcasted, they are accumulated in each listener and each listening thread processes them.
The flags in the Thread structure are the mask of the IDs of the event sources who broadcasted something, those wakeup the thread that then retrieves the flags in the listener. Note that the types are different.

Giovanni