event.h¶
Event API.
-
THREAD_FLAG_EVENT
¶ Thread flag use to notify available events in an event queue.
1
(0x1)
-
EVENT_QUEUE_INIT
¶ event_queue_t static initializer
1
{ .waiter = (thread_t *)sched_active_thread }
-
void(*
event_handler_t
()¶ event handler type definition
-
void
event_queue_init
(event_queue_t * queue)¶ Initialize an event queue.
This will set the calling thread as owner of
queue
.Parameters
queue: event queue object to initialize
-
void
event_post
(event_queue_t * queue,event.h::event_t
* event)¶ Queue an event.
The given event will be posted on the given
queue
. If the event is already queued when calling this function, the event will not be touched and remain in the previous position on the queue. So reposting an event while it is already on the queue will have no effect.Parameters
queue: event queue to queue event in event: event to queue in event queue
-
void
event_cancel
(event_queue_t * queue,event.h::event_t
* event)¶ Cancel a queued event.
This will remove a queued event from an event queue.
Note
Due to the underlying list implementation, this will run in O(n).
Parameters
queue: event queue to remove event from event: event to remove from queue
-
event.h::event_t
*event_get
(event_queue_t * queue)¶ Get next event from event queue, non-blocking.
In order to handle an event retrieved using this function, call event->handler(event).
Parameters
queue: event queue to get event from Return values
- pointer to next event
- NULL if no event available
-
event.h::event_t
*event_wait
(event_queue_t * queue)¶ Get next event from event queue, blocking.
This function will block until an event becomes available.
In order to handle an event retrieved using this function, call event->handler(event).
Parameters
queue: event queue to get event from Return values
- pointer to next event
-
void
event_loop
(event_queue_t * queue)¶ Simple event loop.
This function will forever sit in a loop, waiting for events to be queued and executing their handlers.
It is pretty much defined as:
1 2 3
while ((event = event_wait(queue))) { event->handler(event); }
Parameters
queue: event queue to process
-
struct
event
¶ event structure
-
clist.h::clist_node_t
list_node
¶ event queue list entry
-
event.h::event_handler_t
handler
¶ pointer to event handler function
-
-
struct
event_queue_t
¶ event queue structure
-
clist.h::clist_node_t
event_list
¶ list of queued events
-
sched.h::thread_t
*waiter
¶ thread ownning event queue
-