2
* ivykis, an event handling library
3
* Copyright (C) 2002, 2003, 2009 Lennert Buytenhek
4
* Dedicated to Marija Kulikova.
6
* This library is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License version
8
* 2.1 as published by the Free Software Foundation.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Lesser General Public License version 2.1 for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License version 2.1 along with this library; if not, write to the
17
* Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
18
* Boston, MA 02110-1301, USA.
33
struct iv_fd_ *handled_fd;
38
struct iv_list_head tasks;
44
struct ratnode *timer_root;
48
#ifdef HAVE_SYS_DEVPOLL_H
51
struct iv_avl_tree fds;
53
struct iv_list_head notify;
57
#ifdef HAVE_EPOLL_CREATE
61
struct iv_list_head notify;
69
struct iv_list_head notify;
78
int num_registered_fds;
82
#ifdef HAVE_PORT_CREATE
86
struct iv_list_head notify;
92
struct iv_avl_tree fds;
102
extern __thread struct iv_state *__st;
104
static inline struct iv_state *iv_get_state(void)
111
extern pthread_key_t iv_state_key;
113
static inline struct iv_state *iv_get_state(void)
115
return pthread_getspecific(iv_state_key);
119
static inline void barrier(void)
121
__asm__ __volatile__("" : : : "memory");
126
* Private versions of the fd/task/timer structures, exposing their
127
* internal state. The user data fields of these structures MUST
128
* match the definitions in the public header file iv.h.
136
void (*handler_in)(void *);
137
void (*handler_out)(void *);
138
void (*handler_err)(void *);
141
* If this fd gathered any events during this polling round,
142
* fd->list_active will be on iv_main()'s active list, and
143
* fd->ready_bands will indicate which bands are currently
146
struct iv_list_head list_active;
147
unsigned ready_bands:3;
150
* Reflects whether the fd has been registered with
151
* iv_fd_register(). Will be zero in ->notify_fd() if the
152
* fd is being unregistered.
154
unsigned registered:1;
157
* ->wanted_bands is set by the ivykis core to indicate
158
* which bands currenty have handlers registered for them.
160
unsigned wanted_bands:3;
163
* ->registered_bands is maintained by the poll method to
164
* indicate which bands are currently registered with the
165
* kernel, so that the ivykis core knows when to call
166
* the poll method's ->notify_fd() on an fd.
168
unsigned registered_bands:3;
170
#if defined(HAVE_SYS_DEVPOLL_H) || defined(HAVE_EPOLL_CREATE) || \
171
defined(HAVE_KQUEUE) || defined(HAVE_PORT_CREATE)
173
* ->list_notify is used by poll methods that defer updating
174
* kernel registrations to ->poll() time.
176
struct iv_list_head list_notify;
180
* This is for state internal to some of the poll methods:
181
* ->avl_node is used by poll methods that maintain an
182
* internal fd tree, and ->index is used by iv_method_poll
183
* to maintain the index of this fd in the list of pollfds.
186
#if defined(HAVE_SYS_DEVPOLL_H) || defined(NEED_SELECT)
187
struct iv_avl_node avl_node;
200
void (*handler)(void *);
205
struct iv_list_head list;
212
struct timespec expires;
214
void (*handler)(void *);
224
* Misc internal stuff.
230
struct iv_poll_method {
232
int (*init)(struct iv_state *st);
233
void (*poll)(struct iv_state *st,
234
struct iv_list_head *active, struct timespec *to);
235
void (*register_fd)(struct iv_state *st, struct iv_fd_ *fd);
236
void (*unregister_fd)(struct iv_state *st, struct iv_fd_ *fd);
237
void (*notify_fd)(struct iv_state *st, struct iv_fd_ *fd);
238
int (*notify_fd_sync)(struct iv_state *st, struct iv_fd_ *fd);
239
void (*deinit)(struct iv_state *st);
243
__iv_list_steal_elements(struct iv_list_head *oldh, struct iv_list_head *newh)
245
struct iv_list_head *first = oldh->next;
246
struct iv_list_head *last = oldh->prev;
251
newh->next = oldh->next;
252
newh->prev = oldh->prev;
260
extern struct iv_poll_method *method;
263
extern struct iv_poll_method iv_method_dev_poll;
264
extern struct iv_poll_method iv_method_epoll;
265
extern struct iv_poll_method iv_method_kqueue;
266
extern struct iv_poll_method iv_method_poll;
267
extern struct iv_poll_method iv_method_port;
268
extern struct iv_poll_method iv_method_select;
272
struct iv_fd_ *iv_fd_avl_find(struct iv_avl_tree *root, int fd);
273
int iv_fd_avl_compare(struct iv_avl_node *_a, struct iv_avl_node *_b);
274
void iv_fd_make_ready(struct iv_list_head *active,
275
struct iv_fd_ *fd, int bands);
278
void iv_task_init(struct iv_state *st);
279
int iv_pending_tasks(struct iv_state *st);
280
void iv_run_tasks(struct iv_state *st);
283
void __iv_invalidate_now(struct iv_state *st);
284
void iv_timer_init(struct iv_state *st);
285
int iv_pending_timers(struct iv_state *st);
286
int iv_get_soonest_timeout(struct iv_state *st, struct timespec *to);
287
void iv_run_timers(struct iv_state *st);
288
void iv_timer_deinit(struct iv_state *st);
291
int iv_tls_total_state_size(void);
292
void iv_tls_thread_init(struct iv_state *st);
293
void iv_tls_thread_deinit(struct iv_state *st);