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 
245 event_t *event_wait_multi(event_queue_t *queues, size_t n_queues);
246 
261 static inline event_t *event_wait(event_queue_t *queue)
262 {
263  return event_wait_multi(queue, 1);
264 }
265 
266 #if defined(MODULE_XTIMER) || defined(DOXYGEN)
267 
276 event_t *event_wait_timeout(event_queue_t *queue, uint32_t timeout);
277 
287 event_t *event_wait_timeout64(event_queue_t *queue, uint64_t timeout);
288 #endif
289 
311 void event_loop_multi(event_queue_t *queues, size_t n_queues);
312 
329 static inline void event_loop(event_queue_t *queue)
330 {
331  event_loop_multi(queue, 1);
332 }
333 
334 #ifdef __cplusplus
335 }
336 #endif
337 #endif /* EVENT_H */
338 
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.
void event_loop_multi(event_queue_t *queues, size_t n_queues)
Simple event loop with multiple queues.
clist_node_t list_node
event queue list entry
Definition: event.h:140
event structure
Definition: event.h:139
event_t * event_wait_timeout64(event_queue_t *queue, uint64_t timeout)
Get next event from event queue, blocking until timeout expires.
void event_post(event_queue_t *queue, event_t *event)
Queue an event.
event_t * event_wait_multi(event_queue_t *queues, size_t n_queues)
Get next event from the given event queues, 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.
static void event_loop(event_queue_t *queue)
Simple event loop.
Definition: event.h:329
Circular linked list.
thread_t * waiter
thread ownning event queue
Definition: event.h:149
IRQ driver interface.
static event_t * event_wait(event_queue_t *queue)
Get next event from event queue, blocking.
Definition: event.h:261
clist_node_t event_list
list of queued events
Definition: event.h:148