event.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
89 #ifndef EVENT_H
90 #define EVENT_H
91 
92 #include <stdint.h>
93 
94 #include "irq.h"
95 #include "thread_flags.h"
96 #include "clist.h"
97 
98 #ifdef __cplusplus
99 extern "C" {
100 #endif
101 
102 #ifndef THREAD_FLAG_EVENT
103 
106 #define THREAD_FLAG_EVENT (0x1)
107 #endif
108 
112 #define EVENT_QUEUE_INIT { .waiter = (thread_t *)sched_active_thread }
113 
117 typedef struct event event_t;
118 
122 typedef void (*event_handler_t)(event_t *);
123 
127 struct event {
130 };
131 
135 typedef struct {
138 } event_queue_t;
139 
147 void event_queue_init(event_queue_t *queue);
148 
155 void event_post(event_queue_t *queue, event_t *event);
156 
167 void event_cancel(event_queue_t *queue, event_t *event);
168 
181 
195 
212 void event_loop(event_queue_t *queue);
213 
214 #ifdef __cplusplus
215 }
216 #endif
217 #endif /* EVENT_H */
218 
event_t * event_get(event_queue_t *queue)
Get next event from event queue, non-blocking.
event_handler_t handler
pointer to event handler function
Definition: event.h:129
clist_node_t list_node
event queue list entry
Definition: event.h:128
event structure
Definition: event.h:127
void event_post(event_queue_t *queue, event_t *event)
Queue an event.
event_t * event_wait(event_queue_t *queue)
Get next event from event queue, blocking.
thread_t holds thread&#39;s context data.
Definition: thread.h:178
void event_cancel(event_queue_t *queue, event_t *event)
Cancel a queued event.
Thread Flags API.
void(* event_handler_t)(event_t *)
event handler type definition
Definition: event.h:122
List node structure.
Definition: list.h:40
event queue structure
Definition: event.h:135
void event_queue_init(event_queue_t *queue)
Initialize an event queue.
void event_loop(event_queue_t *queue)
Simple event loop.
Circular linked list.
thread_t * waiter
thread ownning event queue
Definition: event.h:137
IRQ driver interface.
clist_node_t event_list
list of queued events
Definition: event.h:136