Is chEvtBroadcastFlagsI() correct ?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
kunilkuda
Posts: 4
Joined: Thu Jun 12, 2014 11:02 am

Is chEvtBroadcastFlagsI() correct ?

Post 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
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Is chEvtBroadcastFlagsI() correct ?

Post 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
Post Reply