[En-Nut-Discussion] RFC: Wait for Multiple Events
Matthias Ringwald
mringwal at inf.ethz.ch
Wed Apr 26 17:41:19 CEST 2006
Hi all,
I'd like to share with you a (I hope) clean & straight & easy
solution to the problem,
that a thread has no easy way to wait for several events to happen
without polling.
RFC: Wait for Multiple Events
It would be useful for a thread to wait on multiple events.
A straight forward way to implement this could be the introduction of
signals. A set of signals, e.g. 16, can be used similar as the
current event queues.
For this to work, a mask of awaited (or triggering) signals need to
be stored in the thread struct (+2 bytes) and to allow for signals to
be sent without anyone waiting, the queue needs to also store a
signal mask (signal queue size = pointer + signal mask = 4 bytes on
AVR).
In the signal post function, the signal queue has to be searched for
the first thread with a matching signal mask and set to runnable.
As this is in the order of threads, I would not use this within IRQs.
But, if the signal queue contains an event queue at the first byte,
NutEventPost|Broadcast can be directly called on a signal queue as
well. In this case, the first or all threads in the queue will be
awaken regardless of the signal settings. Hence NutEventPostIrq can
also be used to wake up the first thread in a signal queue from an
interrupt service handler.
New functions:
NutSignal[Post|Broadcast][async]( SignalQueue, signalNr);
NutSignalWait( SignalQueue, signalPattern);
Thanks for sharing your opinions on this,
Matthias
More information about the En-Nut-Discussion
mailing list