chEvtWaitOne in NIL?

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
Post Reply
awygle
Posts: 32
Joined: Sun Apr 03, 2016 8:39 pm
Has thanked: 6 times
Been thanked: 4 times

chEvtWaitOne in NIL?

Post by awygle »

Hi all,

RT events have three straightforward ways to wait for events - EvtWaitAny, EvtWaitAll, and EvtWaitOne. NIL events have only EvtWaitAny. In looking at the code it seems very easy to add support for WaitOne and WaitAll - is there a reason to leave these out from NIL?

I understand RT events are much more powerful with Event Sources and Listeners enabling many-to-many relationships, and this is not appropriate for NIL, but processing events one at a time in a loop seems to still be simple and useful.

My implementation of chEvtWaitOneTimeout is below - it requires only one more line compared to chEvtWaitAnyTimeout.

Thank you

Code: Select all

eventmask_t chEvtWaitOneTimeout(eventmask_t mask, systime_t timeout) {
  thread_t *ctp = nil.current;
  eventmask_t m;

  chSysLock();
  if ((m = (ctp->epmask & mask)) == (eventmask_t)0) {
    if (TIME_IMMEDIATE == timeout) {
      chSysUnlock();

      return (eventmask_t)0;
    }
    ctp->u1.ewmask = mask;
    if (chSchGoSleepTimeoutS(NIL_STATE_WTOREVT, timeout) < MSG_OK) {
      chSysUnlock();

      return (eventmask_t)0;
    }
    m = ctp->epmask & mask;
  }
  m ^= m & (m - (evtmask_t)1);
  ctp->epmask &= ~m;
  chSysUnlock();

  return m;
}
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chEvtWaitOne in NIL?

Post by Giovanni »

Hi,

I will look into adding those, I am concerned about features creep, NIL is meant to be small.

Giovanni
awygle
Posts: 32
Joined: Sun Apr 03, 2016 8:39 pm
Has thanked: 6 times
Been thanked: 4 times

Re: chEvtWaitOne in NIL?

Post by awygle »

Thanks Giovanni,

I also noticed that there used to be chEvtWaitAnyTimeoutS in NIL but it got removed during the RT4/NIL2 merge - is this because RT did not have such a function? I found it useful when I needed to wait on either a mailbox message or an event - I could raise an event and send a message atomically with chEvtSignalI and chMBPostS, and then receive the message and clear the event atomically with chMBFetchS and chEvtWaitAnyTimeoutS.
Post Reply