Page 1 of 1

chEvtBroadcastFlags doesn't work like I thought it would

Posted: Wed Dec 02, 2015 1:07 am
by mikemoretti
Hi,

So, you can do chEvtRegisterMaskWithFlags, and chEvtBroadcastFlags, which from looking at some of the chibios code in chevent.c (see below) is supposed to notify my thread only when a specific event mask and flag bits are set, which is exactly what it seems to do (through testing it out). However, it also appears to be pooping into the flags even when the eventmask+flags don't match. So if I do a broadcast with other flags, and then the ones I actually want, I get all the stuff I didn't want, and all the stuff I do want, and I can't distinguish wtf really happened. Is it supposed to do this?

Code: Select all

void chEvtBroadcastFlagsI(event_source_t *esp, eventflags_t flags) {
  event_listener_t *elp;

  chDbgCheckClassI();
  chDbgCheck(esp != NULL);

  elp = esp->es_next;
  /*lint -save -e9087 -e740 [11.3, 1.3] Cast required by list handling.*/
  while (elp != (event_listener_t *)esp) {
  /*lint -restore*/
// Hey I'm gonna poop into the flags no matter what!  Maybe this should go just before chEvtSignal below instead?
    elp->el_flags |= flags;
    /* When flags == 0 the thread will always be signaled because the
       source does not emit any flag.*/
    if ((flags == (eventflags_t)0) ||
        ((elp->el_flags & elp->el_wflags) != (eventflags_t)0)) {
      chEvtSignalI(elp->el_listener, elp->el_events);
    }
    elp = elp->el_next;
  }
}


Am I wrong about this? If so, this seems like a not to usable thing.

My use case is this:

I have a keypad task that reads keys and whether they are long-pressed or just pressed. A bunch of other tasks can register to listen for specific keys and keypress or press and hold events. So whenever a keypress or key press and hold happens, I or those key/press bits into a flag that I broadcast. The other tasks wait for events and only get notified when the specific keys / press status they want happen.

Thanks,
-Mike

Re: chEvtBroadcastFlags doesn't work like I thought it would

Posted: Wed Dec 02, 2015 8:58 am
by Giovanni
Hi,

It is the intended behavior, flags are always ORed with the flags mask until the condition is met and the thread is signaled.

Note that nothing forbids adding your own broadcast variant to the application if you need something different.

Giovanni

Re: chEvtBroadcastFlags doesn't work like I thought it would

Posted: Wed Dec 02, 2015 2:12 pm
by mikemoretti
Thanks. I just wanted to make sure that that was the expected behavior so I know if I need to get around it or submit a patch.