when waiting for events, I encounter situations in my project, where the available chEvtWaitXXX() functions do not provide an optimal solution. It's easy to understand with the following example:
Let there be three events with the masks 0x01, 0x10 and 0x20. Depending on the events received, the thread has to execute different actions. More specifically, whenever event 0x01 occurred it has to do something, and when both events 0x10 and 0x20 occurred it has to do something else.
Right now, I could use chEvtWaitOne() or chEvtWaitAny() to achieve the desired behaviour, but both solutions are not optimal. chEvtWaitOne() would return only one flag at a time and the thread has to accumulate combinations (like 0x10 & 0x20) internally, using multiple calls of chEvtWaitOne() and thus introducing overhead. chEvtWaitAny() might wake the thread if only 0x10 or 0x20 occurred as well, and might even return the event mask 0x31 so that the developer has to handle all possible cases and break up the mask manually, eventually causing overhead and potentially introducing nasty bugs.
So my suggestion is to introduce a chEvtWaitXXX() function, which does not take an eventmask_t as argument, but a function pointer of the form
Code: Select all
typedef eventmask_t (*evtcheckfunc)(eventmask_t pending);
For most flexible use, it is also possible to use both arguments - event mask and callback - so the callback is only executed if the pending events are not completely filtered out by the mask.
What's your opinion about this idea?