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;
}