1/** 2 * \file 3 * \brief Event queue 4 */ 5 6/* 7 * Copyright (c) 2010, 2015, ETH Zurich. 8 * All rights reserved. 9 * 10 * This file is distributed under the terms in the attached LICENSE file. 11 * If you do not find this file, copies can be found by writing to: 12 * ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich. Attn: Systems Group. 13 */ 14 15#ifndef BARRELFISH_EVENT_QUEUE_H 16#define BARRELFISH_EVENT_QUEUE_H 17 18#include <sys/cdefs.h> 19 20#include <barrelfish/waitset.h> 21#include <barrelfish/thread_sync.h> 22 23__BEGIN_DECLS 24 25/// What mode does an event queue operate in? 26enum event_queue_mode { 27 /// Run events continuously, as the waitset allows 28 EVENT_QUEUE_CONTINUOUS, 29 30 /// Trigger one event at a time, when event_queue_trigger() is called 31 EVENT_QUEUE_ONESHOT, 32}; 33 34struct event_queue_node { 35 struct event_closure event; 36 struct event_queue_node *next, *prev; 37 bool run; 38}; 39 40struct event_queue { 41 struct thread_mutex mutex; 42 struct waitset *waitset; 43 struct waitset_chanstate waitset_state; 44 struct event_queue_node *head, *tail; 45 enum event_queue_mode mode; 46}; 47 48void event_queue_init(struct event_queue *evq, struct waitset *waitset, 49 enum event_queue_mode mode); 50void event_queue_add(struct event_queue *q, struct event_queue_node *qn, 51 struct event_closure event); 52errval_t event_queue_cancel(struct event_queue *q, struct event_queue_node *qn); 53errval_t event_queue_trigger(struct event_queue *q); 54errval_t event_queue_flush(struct event_queue *q); 55 56__END_DECLS 57 58#endif // BARRELFISH_EVENT_QUEUE_H 59