Event Management
[Nut/OS API]


Detailed Description

Thread synchronization support.

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 Documentation

#define NUT_WAIT_INFINITE   0

Infinite waiting time definition.

Applications should use this value to disable timeout monitoring while waiting for an event.

Examples:
btstreamer/receiver/btreceiver.c.

#define NutEventPostFromIrq ( qp   ) 

Value:

{                                   \
    if (*qp == 0) {                 \
        *qp = SIGNALED;             \
    }                               \
    else if (*qp != SIGNALED) {     \
        NUTTHREADINFO *tp = (NUTTHREADINFO *)(*qp);    \
        tp->td_qpec++;              \
    }                               \
}
Post an event to a specified queue from interrupt context.

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.

Note:
When calling this function, interrupt routines will change the root of an empty event queue to SIGNALED.
Parameters:
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.


Generated on Wed Apr 29 11:12:30 2009 for BTnut System Software by doxygen 1.5.1