event.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Inria
3  * 2017 Kaspar Schleiser <kaspar@schleiser.de>
4  * 2018-2019 Freie Universit├Ąt Berlin
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser
7  * General Public License v2.1. See the file LICENSE in the top level
8  * directory for more details.
9  */
10 
96 #ifndef EVENT_H
97 #define EVENT_H
98 
99 #include <stdint.h>
100 
101 #include "irq.h"
102 #include "thread_flags.h"
103 #include "clist.h"
104 
105 #ifdef __cplusplus
106 extern "C" {
107 #endif
108 
109 #ifndef THREAD_FLAG_EVENT
110 
113 #define THREAD_FLAG_EVENT (0x1)
114 #endif
115 
119 #define EVENT_QUEUE_INIT { .waiter = (thread_t *)sched_active_thread }
120 
124 #define EVENT_QUEUE_INIT_DETACHED { .waiter = NULL }
125 
129 typedef struct event event_t;
130 
134 typedef void (*event_handler_t)(event_t *);
135 
139 struct event {
142 };
143 
147 typedef struct {
150 } event_queue_t;
151 
159 void event_queue_init(event_queue_t *queue);
160 
167 
178 void event_queue_claim(event_queue_t *queue);
179 
191 void event_post(event_queue_t *queue, event_t *event);
192 
203 void event_cancel(event_queue_t *queue, event_t *event);
204 
217 
233 
234 #if defined(MODULE_XTIMER) || defined(DOXYGEN)
235 
244 event_t *event_wait_timeout(event_queue_t *queue, uint32_t timeout);
245 #endif
246 
263 void event_loop(event_queue_t *queue);
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 #endif /* EVENT_H */
269 
void event_queue_init_detached(event_queue_t *queue)
Initialize an event queue not binding it to a thread.
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:141
event_t * event_wait_timeout(event_queue_t *queue, uint32_t timeout)
Get next event from event queue, blocking until timeout expires.
void event_queue_claim(event_queue_t *queue)
Bind an event queue to the calling thread.
clist_node_t list_node
event queue list entry
Definition: event.h:140
event structure
Definition: event.h:139
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:144
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:134
List node structure.
Definition: list.h:40
event queue structure
Definition: event.h:147
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:149
IRQ driver interface.
clist_node_t event_list
list of queued events
Definition: event.h:148