Threads may wait for events from other threads or interrupts or may post or broadcast events to other threads.
Waiting threads line up in priority ordered queues, so more than one thread may wait for the same event.
Events are posted to a waiting queue, moving the thread from waiting (sleeping) state to ready-to-run state. A running thread may also broadcast an event to a specified queue, waking up all threads on that queue.
Usually a woken up thread takes over the CPU, if it's priority is equal or higher than the currently running thread. However, events can be posted asynchronously, in which case the posting thread continues to run. Interrupt routines must always post events asynchronously.
A waiting queue is a simple linked list of waiting threads.
Defines | |
#define | NUT_WAIT_INFINITE 0 |
Infinite waiting time definition. | |
#define | NutEventPostFromIrq(qp) |
Post an event to a specified queue from interrupt context. | |
#define | SIGNALED ((void *)-1) |
Signaled state definition. |
#define NUT_WAIT_INFINITE 0 |
Infinite waiting time definition.
Applications should use this value to disable timeout monitoring while waiting for an event.
#define NutEventPostFromIrq | ( | qp | ) |
Value:
{ \ if (*qp == 0) { \ *qp = SIGNALED; \ } \ else if (*qp != SIGNALED) { \ NUTTHREADINFO *tp = (NUTTHREADINFO *)(*qp); \ tp->td_qpec++; \ } \ }
Wake up the thread with the highest priority waiting on the specified queue. This function is explicitly provided for IRQ handlers to wakeup waiting user threads.
Internally a counter is used to keep track of the posted events. This counter will be examined when the currently running thread is ready to release the CPU.
qp | Identifies the queue an event is posted to. |
#define SIGNALED ((void *)-1) |
Signaled state definition.
The root of an event queue is set to this value if an event is posted to an empty queue. As this may happen during interrupts, the root of an event queue must be considered volatile.
Timer handles in the THREADINFO structure are set to this value if a timeout occured while waiting for an event.