ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.10 by root, Wed Oct 31 07:36:03 2007 UTC vs.
Revision 1.42 by root, Fri Nov 2 20:05:05 2007 UTC

1/*
2 * libev event processing core, watcher management
3 *
4 * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31#if EV_USE_CONFIG_H
32# include "config.h"
33#endif
34
1#include <math.h> 35#include <math.h>
2#include <stdlib.h> 36#include <stdlib.h>
3#include <unistd.h> 37#include <unistd.h>
4#include <fcntl.h> 38#include <fcntl.h>
5#include <signal.h> 39#include <signal.h>
40#include <stddef.h>
6 41
7#include <stdio.h> 42#include <stdio.h>
8 43
9#include <assert.h> 44#include <assert.h>
10#include <errno.h> 45#include <errno.h>
46#include <sys/types.h>
47#include <sys/wait.h>
11#include <sys/time.h> 48#include <sys/time.h>
12#include <time.h> 49#include <time.h>
13 50
51/**/
52
14#ifndef HAVE_MONOTONIC 53#ifndef EV_USE_MONOTONIC
54# define EV_USE_MONOTONIC 1
55#endif
56
57#ifndef EV_USE_SELECT
58# define EV_USE_SELECT 1
59#endif
60
61#ifndef EV_USE_POLL
62# define EV_USE_POLL 0 /* poll is usually slower than select, and not as well tested */
63#endif
64
65#ifndef EV_USE_EPOLL
66# define EV_USE_EPOLL 0
67#endif
68
69#ifndef EV_USE_REALTIME
70# define EV_USE_REALTIME 1
71#endif
72
73/**/
74
15# ifdef CLOCK_MONOTONIC 75#ifndef CLOCK_MONOTONIC
76# undef EV_USE_MONOTONIC
16# define HAVE_MONOTONIC 1 77# define EV_USE_MONOTONIC 0
17# endif 78#endif
18#endif
19 79
20#ifndef HAVE_SELECT
21# define HAVE_SELECT 1
22#endif
23
24#ifndef HAVE_EPOLL
25# define HAVE_EPOLL 0
26#endif
27
28#ifndef HAVE_REALTIME 80#ifndef CLOCK_REALTIME
29# define HAVE_REALTIME 1 /* posix requirement, but might be slower */ 81# undef EV_USE_REALTIME
82# define EV_USE_REALTIME 0
30#endif 83#endif
84
85/**/
31 86
32#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 87#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
33#define MAX_BLOCKTIME 60. 88#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */
89#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
90/*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */
34 91
35#include "ev.h" 92#include "ev.h"
36 93
37struct ev_watcher { 94#if __GNUC__ >= 3
38 EV_WATCHER (ev_watcher); 95# define expect(expr,value) __builtin_expect ((expr),(value))
39}; 96# define inline inline
97#else
98# define expect(expr,value) (expr)
99# define inline static
100#endif
40 101
41struct ev_watcher_list { 102#define expect_false(expr) expect ((expr) != 0, 0)
42 EV_WATCHER_LIST (ev_watcher_list); 103#define expect_true(expr) expect ((expr) != 0, 1)
43}; 104
105#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
106#define ABSPRI(w) ((w)->priority - EV_MINPRI)
44 107
45typedef struct ev_watcher *W; 108typedef struct ev_watcher *W;
46typedef struct ev_watcher_list *WL; 109typedef struct ev_watcher_list *WL;
110typedef struct ev_watcher_time *WT;
47 111
48static ev_tstamp now, diff; /* monotonic clock */ 112static ev_tstamp now_floor, now, diff; /* monotonic clock */
49ev_tstamp ev_now; 113ev_tstamp ev_now;
50int ev_method; 114int ev_method;
51 115
52static int have_monotonic; /* runtime */ 116static int have_monotonic; /* runtime */
53 117
58/*****************************************************************************/ 122/*****************************************************************************/
59 123
60ev_tstamp 124ev_tstamp
61ev_time (void) 125ev_time (void)
62{ 126{
63#if HAVE_REALTIME 127#if EV_USE_REALTIME
64 struct timespec ts; 128 struct timespec ts;
65 clock_gettime (CLOCK_REALTIME, &ts); 129 clock_gettime (CLOCK_REALTIME, &ts);
66 return ts.tv_sec + ts.tv_nsec * 1e-9; 130 return ts.tv_sec + ts.tv_nsec * 1e-9;
67#else 131#else
68 struct timeval tv; 132 struct timeval tv;
72} 136}
73 137
74static ev_tstamp 138static ev_tstamp
75get_clock (void) 139get_clock (void)
76{ 140{
77#if HAVE_MONOTONIC 141#if EV_USE_MONOTONIC
78 if (have_monotonic) 142 if (expect_true (have_monotonic))
79 { 143 {
80 struct timespec ts; 144 struct timespec ts;
81 clock_gettime (CLOCK_MONOTONIC, &ts); 145 clock_gettime (CLOCK_MONOTONIC, &ts);
82 return ts.tv_sec + ts.tv_nsec * 1e-9; 146 return ts.tv_sec + ts.tv_nsec * 1e-9;
83 } 147 }
84#endif 148#endif
85 149
86 return ev_time (); 150 return ev_time ();
87} 151}
88 152
153#define array_roundsize(base,n) ((n) | 4 & ~3)
154
89#define array_needsize(base,cur,cnt,init) \ 155#define array_needsize(base,cur,cnt,init) \
90 if ((cnt) > cur) \ 156 if (expect_false ((cnt) > cur)) \
91 { \ 157 { \
92 int newcnt = cur ? cur << 1 : 16; \ 158 int newcnt = cur; \
93 fprintf (stderr, "resize(" # base ") from %d to %d\n", cur, newcnt);\ 159 do \
160 { \
161 newcnt = array_roundsize (base, newcnt << 1); \
162 } \
163 while ((cnt) > newcnt); \
164 \
94 base = realloc (base, sizeof (*base) * (newcnt)); \ 165 base = realloc (base, sizeof (*base) * (newcnt)); \
95 init (base + cur, newcnt - cur); \ 166 init (base + cur, newcnt - cur); \
96 cur = newcnt; \ 167 cur = newcnt; \
97 } 168 }
98 169
99/*****************************************************************************/ 170/*****************************************************************************/
100 171
101typedef struct 172typedef struct
102{ 173{
103 struct ev_io *head; 174 struct ev_io *head;
104 unsigned char wev, rev; /* want, received event set */ 175 unsigned char events;
176 unsigned char reify;
105} ANFD; 177} ANFD;
106 178
107static ANFD *anfds; 179static ANFD *anfds;
108static int anfdmax; 180static int anfdmax;
109 181
110static int *fdchanges;
111static int fdchangemax, fdchangecnt;
112
113static void 182static void
114anfds_init (ANFD *base, int count) 183anfds_init (ANFD *base, int count)
115{ 184{
116 while (count--) 185 while (count--)
117 { 186 {
118 base->head = 0; 187 base->head = 0;
119 base->wev = base->rev = EV_NONE; 188 base->events = EV_NONE;
189 base->reify = 0;
190
120 ++base; 191 ++base;
121 } 192 }
122} 193}
123 194
124typedef struct 195typedef struct
125{ 196{
126 W w; 197 W w;
127 int events; 198 int events;
128} ANPENDING; 199} ANPENDING;
129 200
130static ANPENDING *pendings; 201static ANPENDING *pendings [NUMPRI];
131static int pendingmax, pendingcnt; 202static int pendingmax [NUMPRI], pendingcnt [NUMPRI];
132 203
133static void 204static void
134event (W w, int events) 205event (W w, int events)
135{ 206{
207 if (w->pending)
208 {
209 pendings [ABSPRI (w)][w->pending - 1].events |= events;
210 return;
211 }
212
136 w->pending = ++pendingcnt; 213 w->pending = ++pendingcnt [ABSPRI (w)];
137 array_needsize (pendings, pendingmax, pendingcnt, ); 214 array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], );
138 pendings [pendingcnt - 1].w = w; 215 pendings [ABSPRI (w)][w->pending - 1].w = w;
139 pendings [pendingcnt - 1].events = events; 216 pendings [ABSPRI (w)][w->pending - 1].events = events;
217}
218
219static void
220queue_events (W *events, int eventcnt, int type)
221{
222 int i;
223
224 for (i = 0; i < eventcnt; ++i)
225 event (events [i], type);
140} 226}
141 227
142static void 228static void
143fd_event (int fd, int events) 229fd_event (int fd, int events)
144{ 230{
152 if (ev) 238 if (ev)
153 event ((W)w, ev); 239 event ((W)w, ev);
154 } 240 }
155} 241}
156 242
243/*****************************************************************************/
244
245static int *fdchanges;
246static int fdchangemax, fdchangecnt;
247
157static void 248static void
158queue_events (W *events, int eventcnt, int type) 249fd_reify (void)
159{ 250{
160 int i; 251 int i;
161 252
162 for (i = 0; i < eventcnt; ++i) 253 for (i = 0; i < fdchangecnt; ++i)
163 event (events [i], type); 254 {
164} 255 int fd = fdchanges [i];
256 ANFD *anfd = anfds + fd;
257 struct ev_io *w;
165 258
166/*****************************************************************************/ 259 int events = 0;
167 260
261 for (w = anfd->head; w; w = w->next)
262 events |= w->events;
263
264 anfd->reify = 0;
265
266 if (anfd->events != events)
267 {
268 method_modify (fd, anfd->events, events);
269 anfd->events = events;
270 }
271 }
272
273 fdchangecnt = 0;
274}
275
276static void
277fd_change (int fd)
278{
279 if (anfds [fd].reify || fdchangecnt < 0)
280 return;
281
282 anfds [fd].reify = 1;
283
284 ++fdchangecnt;
285 array_needsize (fdchanges, fdchangemax, fdchangecnt, );
286 fdchanges [fdchangecnt - 1] = fd;
287}
288
289static void
290fd_kill (int fd)
291{
292 struct ev_io *w;
293
294 printf ("killing fd %d\n", fd);//D
295 while ((w = anfds [fd].head))
296 {
297 ev_io_stop (w);
298 event ((W)w, EV_ERROR | EV_READ | EV_WRITE);
299 }
300}
301
302/* called on EBADF to verify fds */
303static void
304fd_ebadf (void)
305{
306 int fd;
307
308 for (fd = 0; fd < anfdmax; ++fd)
309 if (anfds [fd].events)
310 if (fcntl (fd, F_GETFD) == -1 && errno == EBADF)
311 fd_kill (fd);
312}
313
314/* called on ENOMEM in select/poll to kill some fds and retry */
315static void
316fd_enomem (void)
317{
318 int fd = anfdmax;
319
320 while (fd--)
321 if (anfds [fd].events)
322 {
323 close (fd);
324 fd_kill (fd);
325 return;
326 }
327}
328
329/*****************************************************************************/
330
168static struct ev_timer **atimers; 331static struct ev_timer **timers;
169static int atimermax, atimercnt; 332static int timermax, timercnt;
170 333
171static struct ev_timer **rtimers; 334static struct ev_periodic **periodics;
172static int rtimermax, rtimercnt; 335static int periodicmax, periodiccnt;
173 336
174static void 337static void
175upheap (struct ev_timer **timers, int k) 338upheap (WT *timers, int k)
176{ 339{
177 struct ev_timer *w = timers [k]; 340 WT w = timers [k];
178 341
179 while (k && timers [k >> 1]->at > w->at) 342 while (k && timers [k >> 1]->at > w->at)
180 { 343 {
181 timers [k] = timers [k >> 1]; 344 timers [k] = timers [k >> 1];
182 timers [k]->active = k + 1; 345 timers [k]->active = k + 1;
187 timers [k]->active = k + 1; 350 timers [k]->active = k + 1;
188 351
189} 352}
190 353
191static void 354static void
192downheap (struct ev_timer **timers, int N, int k) 355downheap (WT *timers, int N, int k)
193{ 356{
194 struct ev_timer *w = timers [k]; 357 WT w = timers [k];
195 358
196 while (k < (N >> 1)) 359 while (k < (N >> 1))
197 { 360 {
198 int j = k << 1; 361 int j = k << 1;
199 362
215/*****************************************************************************/ 378/*****************************************************************************/
216 379
217typedef struct 380typedef struct
218{ 381{
219 struct ev_signal *head; 382 struct ev_signal *head;
220 sig_atomic_t gotsig; 383 sig_atomic_t volatile gotsig;
221} ANSIG; 384} ANSIG;
222 385
223static ANSIG *signals; 386static ANSIG *signals;
224static int signalmax; 387static int signalmax;
225 388
226static int sigpipe [2]; 389static int sigpipe [2];
227static sig_atomic_t gotsig; 390static sig_atomic_t volatile gotsig;
228static struct ev_io sigev; 391static struct ev_io sigev;
229 392
230static void 393static void
231signals_init (ANSIG *base, int count) 394signals_init (ANSIG *base, int count)
232{ 395{
233 while (count--) 396 while (count--)
234 { 397 {
235 base->head = 0; 398 base->head = 0;
236 base->gotsig = 0; 399 base->gotsig = 0;
400
237 ++base; 401 ++base;
238 } 402 }
239} 403}
240 404
241static void 405static void
244 signals [signum - 1].gotsig = 1; 408 signals [signum - 1].gotsig = 1;
245 409
246 if (!gotsig) 410 if (!gotsig)
247 { 411 {
248 gotsig = 1; 412 gotsig = 1;
249 write (sigpipe [1], &gotsig, 1); 413 write (sigpipe [1], &signum, 1);
250 } 414 }
251} 415}
252 416
253static void 417static void
254sigcb (struct ev_io *iow, int revents) 418sigcb (struct ev_io *iow, int revents)
255{ 419{
256 struct ev_signal *w; 420 struct ev_signal *w;
257 int sig; 421 int signum;
258 422
423 read (sigpipe [0], &revents, 1);
259 gotsig = 0; 424 gotsig = 0;
260 read (sigpipe [0], &revents, 1);
261 425
262 for (sig = signalmax; sig--; ) 426 for (signum = signalmax; signum--; )
263 if (signals [sig].gotsig) 427 if (signals [signum].gotsig)
264 { 428 {
265 signals [sig].gotsig = 0; 429 signals [signum].gotsig = 0;
266 430
267 for (w = signals [sig].head; w; w = w->next) 431 for (w = signals [signum].head; w; w = w->next)
268 event ((W)w, EV_SIGNAL); 432 event ((W)w, EV_SIGNAL);
269 } 433 }
270} 434}
271 435
272static void 436static void
277 441
278 /* rather than sort out wether we really need nb, set it */ 442 /* rather than sort out wether we really need nb, set it */
279 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK); 443 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK);
280 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); 444 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK);
281 445
282 evio_set (&sigev, sigpipe [0], EV_READ); 446 ev_io_set (&sigev, sigpipe [0], EV_READ);
283 evio_start (&sigev); 447 ev_io_start (&sigev);
284} 448}
285 449
286/*****************************************************************************/ 450/*****************************************************************************/
287 451
288static struct ev_idle **idles; 452static struct ev_idle **idles;
289static int idlemax, idlecnt; 453static int idlemax, idlecnt;
290 454
455static struct ev_prepare **prepares;
456static int preparemax, preparecnt;
457
291static struct ev_check **checks; 458static struct ev_check **checks;
292static int checkmax, checkcnt; 459static int checkmax, checkcnt;
293 460
294/*****************************************************************************/ 461/*****************************************************************************/
295 462
463static struct ev_child *childs [PID_HASHSIZE];
464static struct ev_signal childev;
465
466#ifndef WCONTINUED
467# define WCONTINUED 0
468#endif
469
470static void
471childcb (struct ev_signal *sw, int revents)
472{
473 struct ev_child *w;
474 int pid, status;
475
476 while ((pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)) != -1)
477 for (w = childs [pid & (PID_HASHSIZE - 1)]; w; w = w->next)
478 if (w->pid == pid || !w->pid)
479 {
480 w->status = status;
481 event ((W)w, EV_CHILD);
482 }
483}
484
485/*****************************************************************************/
486
296#if HAVE_EPOLL 487#if EV_USE_EPOLL
297# include "ev_epoll.c" 488# include "ev_epoll.c"
298#endif 489#endif
490#if EV_USE_POLL
491# include "ev_poll.c"
492#endif
299#if HAVE_SELECT 493#if EV_USE_SELECT
300# include "ev_select.c" 494# include "ev_select.c"
301#endif 495#endif
302 496
497int
498ev_version_major (void)
499{
500 return EV_VERSION_MAJOR;
501}
502
503int
504ev_version_minor (void)
505{
506 return EV_VERSION_MINOR;
507}
508
509/* return true if we are running with elevated privileges and ignore env variables */
510static int
511enable_secure ()
512{
513 return getuid () != geteuid ()
514 || getgid () != getegid ();
515}
516
303int ev_init (int flags) 517int ev_init (int methods)
304{ 518{
305#if HAVE_MONOTONIC
306 {
307 struct timespec ts;
308 if (!clock_gettime (CLOCK_MONOTONIC, &ts))
309 have_monotonic = 1;
310 }
311#endif
312
313 ev_now = ev_time ();
314 now = get_clock ();
315 diff = ev_now - now;
316
317 if (pipe (sigpipe))
318 return 0;
319
320 ev_method = EVMETHOD_NONE;
321#if HAVE_EPOLL
322 if (ev_method == EVMETHOD_NONE) epoll_init (flags);
323#endif
324#if HAVE_SELECT
325 if (ev_method == EVMETHOD_NONE) select_init (flags);
326#endif
327
328 if (ev_method) 519 if (!ev_method)
520 {
521#if EV_USE_MONOTONIC
329 { 522 {
523 struct timespec ts;
524 if (!clock_gettime (CLOCK_MONOTONIC, &ts))
525 have_monotonic = 1;
526 }
527#endif
528
529 ev_now = ev_time ();
530 now = get_clock ();
531 now_floor = now;
532 diff = ev_now - now;
533
534 if (pipe (sigpipe))
535 return 0;
536
537 if (methods == EVMETHOD_AUTO)
538 if (!enable_secure () && getenv ("LIBEV_METHODS"))
539 methods = atoi (getenv ("LIBEV_METHODS"));
540 else
541 methods = EVMETHOD_ANY;
542
543 ev_method = 0;
544#if EV_USE_EPOLL
545 if (!ev_method && (methods & EVMETHOD_EPOLL )) epoll_init (methods);
546#endif
547#if EV_USE_POLL
548 if (!ev_method && (methods & EVMETHOD_POLL )) poll_init (methods);
549#endif
550#if EV_USE_SELECT
551 if (!ev_method && (methods & EVMETHOD_SELECT)) select_init (methods);
552#endif
553
554 if (ev_method)
555 {
330 evw_init (&sigev, sigcb, 0); 556 ev_watcher_init (&sigev, sigcb);
331 siginit (); 557 siginit ();
558
559 ev_signal_init (&childev, childcb, SIGCHLD);
560 ev_signal_start (&childev);
561 }
332 } 562 }
333 563
334 return ev_method; 564 return ev_method;
335} 565}
336 566
337/*****************************************************************************/ 567/*****************************************************************************/
338 568
339void ev_prefork (void) 569void
570ev_fork_prepare (void)
340{ 571{
572 /* nop */
341} 573}
342 574
575void
343void ev_postfork_parent (void) 576ev_fork_parent (void)
344{ 577{
578 /* nop */
345} 579}
346 580
581void
347void ev_postfork_child (void) 582ev_fork_child (void)
348{ 583{
349#if HAVE_EPOLL 584#if EV_USE_EPOLL
350 if (ev_method == EVMETHOD_EPOLL) 585 if (ev_method == EVMETHOD_EPOLL)
351 epoll_postfork_child (); 586 epoll_postfork_child ();
352#endif 587#endif
353 588
354 evio_stop (&sigev); 589 ev_io_stop (&sigev);
355 close (sigpipe [0]); 590 close (sigpipe [0]);
356 close (sigpipe [1]); 591 close (sigpipe [1]);
357 pipe (sigpipe); 592 pipe (sigpipe);
358 siginit (); 593 siginit ();
359} 594}
360 595
361/*****************************************************************************/ 596/*****************************************************************************/
362 597
363static void 598static void
364fd_reify (void) 599call_pending (void)
365{ 600{
366 int i; 601 int pri;
367 602
368 for (i = 0; i < fdchangecnt; ++i) 603 for (pri = NUMPRI; pri--; )
369 { 604 while (pendingcnt [pri])
370 int fd = fdchanges [i];
371 ANFD *anfd = anfds + fd;
372 struct ev_io *w;
373
374 int wev = 0;
375
376 for (w = anfd->head; w; w = w->next)
377 wev |= w->events;
378
379 if (anfd->wev != wev)
380 { 605 {
381 method_modify (fd, anfd->wev, wev); 606 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
382 anfd->wev = wev;
383 }
384 }
385 607
386 fdchangecnt = 0;
387}
388
389static void
390call_pending ()
391{
392 int i;
393
394 for (i = 0; i < pendingcnt; ++i)
395 {
396 ANPENDING *p = pendings + i;
397
398 if (p->w) 608 if (p->w)
399 { 609 {
400 p->w->pending = 0; 610 p->w->pending = 0;
401 p->w->cb (p->w, p->events); 611 p->w->cb (p->w, p->events);
402 } 612 }
403 } 613 }
404
405 pendingcnt = 0;
406} 614}
407 615
408static void 616static void
409timers_reify (struct ev_timer **timers, int timercnt, ev_tstamp now) 617timers_reify (void)
410{ 618{
411 while (timercnt && timers [0]->at <= now) 619 while (timercnt && timers [0]->at <= now)
412 { 620 {
413 struct ev_timer *w = timers [0]; 621 struct ev_timer *w = timers [0];
414 622
415 /* first reschedule or stop timer */ 623 /* first reschedule or stop timer */
416 if (w->repeat) 624 if (w->repeat)
417 { 625 {
418 if (w->is_abs) 626 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.));
419 w->at += floor ((now - w->at) / w->repeat + 1.) * w->repeat;
420 else
421 w->at = now + w->repeat; 627 w->at = now + w->repeat;
422
423 assert (w->at > now);
424
425 downheap (timers, timercnt, 0); 628 downheap ((WT *)timers, timercnt, 0);
426 } 629 }
427 else 630 else
428 {
429 evtimer_stop (w); /* nonrepeating: stop timer */ 631 ev_timer_stop (w); /* nonrepeating: stop timer */
430 --timercnt; /* maybe pass by reference instead? */
431 }
432 632
433 event ((W)w, EV_TIMEOUT); 633 event ((W)w, EV_TIMEOUT);
434 } 634 }
435} 635}
436 636
437static void 637static void
438time_update () 638periodics_reify (void)
639{
640 while (periodiccnt && periodics [0]->at <= ev_now)
641 {
642 struct ev_periodic *w = periodics [0];
643
644 /* first reschedule or stop timer */
645 if (w->interval)
646 {
647 w->at += floor ((ev_now - w->at) / w->interval + 1.) * w->interval;
648 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", w->at > ev_now));
649 downheap ((WT *)periodics, periodiccnt, 0);
650 }
651 else
652 ev_periodic_stop (w); /* nonrepeating: stop timer */
653
654 event ((W)w, EV_PERIODIC);
655 }
656}
657
658static void
659periodics_reschedule (ev_tstamp diff)
439{ 660{
440 int i; 661 int i;
441 ev_now = ev_time ();
442 662
443 if (have_monotonic) 663 /* adjust periodics after time jump */
664 for (i = 0; i < periodiccnt; ++i)
444 { 665 {
445 ev_tstamp odiff = diff; 666 struct ev_periodic *w = periodics [i];
446 667
447 /* detecting time jumps is much more difficult */ 668 if (w->interval)
448 for (i = 2; --i; ) /* loop a few times, before making important decisions */
449 {
450 now = get_clock ();
451 diff = ev_now - now;
452
453 if (fabs (odiff - diff) < MIN_TIMEJUMP)
454 return; /* all is well */
455
456 ev_now = ev_time ();
457 } 669 {
670 ev_tstamp diff = ceil ((ev_now - w->at) / w->interval) * w->interval;
458 671
459 /* time jump detected, reschedule atimers */ 672 if (fabs (diff) >= 1e-4)
460 for (i = 0; i < atimercnt; ++i) 673 {
674 ev_periodic_stop (w);
675 ev_periodic_start (w);
676
677 i = 0; /* restart loop, inefficient, but time jumps should be rare */
678 }
461 { 679 }
462 struct ev_timer *w = atimers [i]; 680 }
463 w->at += ceil ((ev_now - w->at) / w->repeat + 1.) * w->repeat; 681}
464 } 682
683static int
684time_update_monotonic (void)
685{
686 now = get_clock ();
687
688 if (expect_true (now - now_floor < MIN_TIMEJUMP * .5))
689 {
690 ev_now = now + diff;
691 return 0;
465 } 692 }
466 else 693 else
467 { 694 {
695 now_floor = now;
696 ev_now = ev_time ();
697 return 1;
698 }
699}
700
701static void
702time_update (void)
703{
704 int i;
705
706#if EV_USE_MONOTONIC
707 if (expect_true (have_monotonic))
708 {
709 if (time_update_monotonic ())
710 {
711 ev_tstamp odiff = diff;
712
713 for (i = 4; --i; ) /* loop a few times, before making important decisions */
714 {
715 diff = ev_now - now;
716
717 if (fabs (odiff - diff) < MIN_TIMEJUMP)
718 return; /* all is well */
719
720 ev_now = ev_time ();
721 now = get_clock ();
722 now_floor = now;
723 }
724
725 periodics_reschedule (diff - odiff);
726 /* no timer adjustment, as the monotonic clock doesn't jump */
727 }
728 }
729 else
730#endif
731 {
732 ev_now = ev_time ();
733
468 if (now > ev_now || now < ev_now - MAX_BLOCKTIME - MIN_TIMEJUMP) 734 if (expect_false (now > ev_now || now < ev_now - MAX_BLOCKTIME - MIN_TIMEJUMP))
469 /* time jump detected, adjust rtimers */ 735 {
736 periodics_reschedule (ev_now - now);
737
738 /* adjust timers. this is easy, as the offset is the same for all */
470 for (i = 0; i < rtimercnt; ++i) 739 for (i = 0; i < timercnt; ++i)
471 rtimers [i]->at += ev_now - now; 740 timers [i]->at += diff;
741 }
472 742
473 now = ev_now; 743 now = ev_now;
474 } 744 }
475} 745}
476 746
477int ev_loop_done; 747int ev_loop_done;
478 748
479void ev_loop (int flags) 749void ev_loop (int flags)
480{ 750{
481 double block; 751 double block;
482 ev_loop_done = flags & EVLOOP_ONESHOT; 752 ev_loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0;
483
484 if (checkcnt)
485 {
486 queue_events ((W *)checks, checkcnt, EV_CHECK);
487 call_pending ();
488 }
489 753
490 do 754 do
491 { 755 {
756 /* queue check watchers (and execute them) */
757 if (expect_false (preparecnt))
758 {
759 queue_events ((W *)prepares, preparecnt, EV_PREPARE);
760 call_pending ();
761 }
762
492 /* update fd-related kernel structures */ 763 /* update fd-related kernel structures */
493 fd_reify (); 764 fd_reify ();
494 765
495 /* calculate blocking time */ 766 /* calculate blocking time */
767
768 /* we only need this for !monotonic clockor timers, but as we basically
769 always have timers, we just calculate it always */
770#if EV_USE_MONOTONIC
771 if (expect_true (have_monotonic))
772 time_update_monotonic ();
773 else
774#endif
775 {
776 ev_now = ev_time ();
777 now = ev_now;
778 }
779
496 if (flags & EVLOOP_NONBLOCK || idlecnt) 780 if (flags & EVLOOP_NONBLOCK || idlecnt)
497 block = 0.; 781 block = 0.;
498 else 782 else
499 { 783 {
500 block = MAX_BLOCKTIME; 784 block = MAX_BLOCKTIME;
501 785
502 if (rtimercnt) 786 if (timercnt)
503 { 787 {
504 ev_tstamp to = rtimers [0]->at - get_clock () + method_fudge; 788 ev_tstamp to = timers [0]->at - now + method_fudge;
505 if (block > to) block = to; 789 if (block > to) block = to;
506 } 790 }
507 791
508 if (atimercnt) 792 if (periodiccnt)
509 { 793 {
510 ev_tstamp to = atimers [0]->at - ev_time () + method_fudge; 794 ev_tstamp to = periodics [0]->at - ev_now + method_fudge;
511 if (block > to) block = to; 795 if (block > to) block = to;
512 } 796 }
513 797
514 if (block < 0.) block = 0.; 798 if (block < 0.) block = 0.;
515 } 799 }
518 802
519 /* update ev_now, do magic */ 803 /* update ev_now, do magic */
520 time_update (); 804 time_update ();
521 805
522 /* queue pending timers and reschedule them */ 806 /* queue pending timers and reschedule them */
523 /* absolute timers first */ 807 timers_reify (); /* relative timers called last */
524 timers_reify (atimers, atimercnt, ev_now); 808 periodics_reify (); /* absolute timers called first */
525 /* relative timers second */
526 timers_reify (rtimers, rtimercnt, now);
527 809
528 /* queue idle watchers unless io or timers are pending */ 810 /* queue idle watchers unless io or timers are pending */
529 if (!pendingcnt) 811 if (!pendingcnt)
530 queue_events ((W *)idles, idlecnt, EV_IDLE); 812 queue_events ((W *)idles, idlecnt, EV_IDLE);
531 813
532 /* queue check and possibly idle watchers */ 814 /* queue check watchers, to be executed first */
815 if (checkcnt)
533 queue_events ((W *)checks, checkcnt, EV_CHECK); 816 queue_events ((W *)checks, checkcnt, EV_CHECK);
534 817
535 call_pending (); 818 call_pending ();
536 } 819 }
537 while (!ev_loop_done); 820 while (!ev_loop_done);
821
822 if (ev_loop_done != 2)
823 ev_loop_done = 0;
538} 824}
539 825
540/*****************************************************************************/ 826/*****************************************************************************/
541 827
542static void 828static void
560 head = &(*head)->next; 846 head = &(*head)->next;
561 } 847 }
562} 848}
563 849
564static void 850static void
851ev_clear_pending (W w)
852{
853 if (w->pending)
854 {
855 pendings [ABSPRI (w)][w->pending - 1].w = 0;
856 w->pending = 0;
857 }
858}
859
860static void
565ev_start (W w, int active) 861ev_start (W w, int active)
566{ 862{
567 w->pending = 0;
568 w->active = active; 863 w->active = active;
569} 864}
570 865
571static void 866static void
572ev_stop (W w) 867ev_stop (W w)
573{ 868{
574 if (w->pending)
575 pendings [w->pending - 1].w = 0;
576
577 w->active = 0; 869 w->active = 0;
578 /* nop */
579} 870}
580 871
581/*****************************************************************************/ 872/*****************************************************************************/
582 873
583void 874void
584evio_start (struct ev_io *w) 875ev_io_start (struct ev_io *w)
585{ 876{
877 int fd = w->fd;
878
586 if (ev_is_active (w)) 879 if (ev_is_active (w))
587 return; 880 return;
588 881
589 int fd = w->fd; 882 assert (("ev_io_start called with negative fd", fd >= 0));
590 883
591 ev_start ((W)w, 1); 884 ev_start ((W)w, 1);
592 array_needsize (anfds, anfdmax, fd + 1, anfds_init); 885 array_needsize (anfds, anfdmax, fd + 1, anfds_init);
593 wlist_add ((WL *)&anfds[fd].head, (WL)w); 886 wlist_add ((WL *)&anfds[fd].head, (WL)w);
594 887
595 ++fdchangecnt; 888 fd_change (fd);
596 array_needsize (fdchanges, fdchangemax, fdchangecnt, );
597 fdchanges [fdchangecnt - 1] = fd;
598} 889}
599 890
600void 891void
601evio_stop (struct ev_io *w) 892ev_io_stop (struct ev_io *w)
602{ 893{
894 ev_clear_pending ((W)w);
603 if (!ev_is_active (w)) 895 if (!ev_is_active (w))
604 return; 896 return;
605 897
606 wlist_del ((WL *)&anfds[w->fd].head, (WL)w); 898 wlist_del ((WL *)&anfds[w->fd].head, (WL)w);
607 ev_stop ((W)w); 899 ev_stop ((W)w);
608 900
609 ++fdchangecnt; 901 fd_change (w->fd);
610 array_needsize (fdchanges, fdchangemax, fdchangecnt, );
611 fdchanges [fdchangecnt - 1] = w->fd;
612} 902}
613 903
614void 904void
615evtimer_start (struct ev_timer *w) 905ev_timer_start (struct ev_timer *w)
616{ 906{
617 if (ev_is_active (w)) 907 if (ev_is_active (w))
618 return; 908 return;
619 909
620 if (w->is_abs) 910 w->at += now;
911
912 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
913
914 ev_start ((W)w, ++timercnt);
915 array_needsize (timers, timermax, timercnt, );
916 timers [timercnt - 1] = w;
917 upheap ((WT *)timers, timercnt - 1);
918}
919
920void
921ev_timer_stop (struct ev_timer *w)
922{
923 ev_clear_pending ((W)w);
924 if (!ev_is_active (w))
925 return;
926
927 if (w->active < timercnt--)
928 {
929 timers [w->active - 1] = timers [timercnt];
930 downheap ((WT *)timers, timercnt, w->active - 1);
621 { 931 }
622 /* this formula differs from the one in timer_reify becuse we do not round up */ 932
933 w->at = w->repeat;
934
935 ev_stop ((W)w);
936}
937
938void
939ev_timer_again (struct ev_timer *w)
940{
941 if (ev_is_active (w))
942 {
623 if (w->repeat) 943 if (w->repeat)
944 {
945 w->at = now + w->repeat;
946 downheap ((WT *)timers, timercnt, w->active - 1);
947 }
948 else
949 ev_timer_stop (w);
950 }
951 else if (w->repeat)
952 ev_timer_start (w);
953}
954
955void
956ev_periodic_start (struct ev_periodic *w)
957{
958 if (ev_is_active (w))
959 return;
960
961 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.));
962
963 /* this formula differs from the one in periodic_reify because we do not always round up */
964 if (w->interval)
624 w->at += ceil ((ev_now - w->at) / w->repeat) * w->repeat; 965 w->at += ceil ((ev_now - w->at) / w->interval) * w->interval;
625 966
626 ev_start ((W)w, ++atimercnt); 967 ev_start ((W)w, ++periodiccnt);
627 array_needsize (atimers, atimermax, atimercnt, ); 968 array_needsize (periodics, periodicmax, periodiccnt, );
628 atimers [atimercnt - 1] = w; 969 periodics [periodiccnt - 1] = w;
629 upheap (atimers, atimercnt - 1); 970 upheap ((WT *)periodics, periodiccnt - 1);
630 }
631 else
632 {
633 w->at += now;
634
635 ev_start ((W)w, ++rtimercnt);
636 array_needsize (rtimers, rtimermax, rtimercnt, );
637 rtimers [rtimercnt - 1] = w;
638 upheap (rtimers, rtimercnt - 1);
639 }
640
641} 971}
642 972
643void 973void
644evtimer_stop (struct ev_timer *w) 974ev_periodic_stop (struct ev_periodic *w)
645{ 975{
976 ev_clear_pending ((W)w);
646 if (!ev_is_active (w)) 977 if (!ev_is_active (w))
647 return; 978 return;
648 979
649 if (w->is_abs)
650 {
651 if (w->active < atimercnt--) 980 if (w->active < periodiccnt--)
652 {
653 atimers [w->active - 1] = atimers [atimercnt];
654 downheap (atimers, atimercnt, w->active - 1);
655 }
656 } 981 {
657 else 982 periodics [w->active - 1] = periodics [periodiccnt];
658 { 983 downheap ((WT *)periodics, periodiccnt, w->active - 1);
659 if (w->active < rtimercnt--)
660 {
661 rtimers [w->active - 1] = rtimers [rtimercnt];
662 downheap (rtimers, rtimercnt, w->active - 1);
663 }
664 } 984 }
665 985
666 ev_stop ((W)w); 986 ev_stop ((W)w);
667} 987}
668 988
669void 989void
670evsignal_start (struct ev_signal *w) 990ev_signal_start (struct ev_signal *w)
671{ 991{
672 if (ev_is_active (w)) 992 if (ev_is_active (w))
673 return; 993 return;
994
995 assert (("ev_signal_start called with illegal signal number", w->signum > 0));
674 996
675 ev_start ((W)w, 1); 997 ev_start ((W)w, 1);
676 array_needsize (signals, signalmax, w->signum, signals_init); 998 array_needsize (signals, signalmax, w->signum, signals_init);
677 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 999 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
678 1000
685 sigaction (w->signum, &sa, 0); 1007 sigaction (w->signum, &sa, 0);
686 } 1008 }
687} 1009}
688 1010
689void 1011void
690evsignal_stop (struct ev_signal *w) 1012ev_signal_stop (struct ev_signal *w)
691{ 1013{
1014 ev_clear_pending ((W)w);
692 if (!ev_is_active (w)) 1015 if (!ev_is_active (w))
693 return; 1016 return;
694 1017
695 wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); 1018 wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w);
696 ev_stop ((W)w); 1019 ev_stop ((W)w);
697 1020
698 if (!signals [w->signum - 1].head) 1021 if (!signals [w->signum - 1].head)
699 signal (w->signum, SIG_DFL); 1022 signal (w->signum, SIG_DFL);
700} 1023}
701 1024
1025void
702void evidle_start (struct ev_idle *w) 1026ev_idle_start (struct ev_idle *w)
703{ 1027{
704 if (ev_is_active (w)) 1028 if (ev_is_active (w))
705 return; 1029 return;
706 1030
707 ev_start ((W)w, ++idlecnt); 1031 ev_start ((W)w, ++idlecnt);
708 array_needsize (idles, idlemax, idlecnt, ); 1032 array_needsize (idles, idlemax, idlecnt, );
709 idles [idlecnt - 1] = w; 1033 idles [idlecnt - 1] = w;
710} 1034}
711 1035
1036void
712void evidle_stop (struct ev_idle *w) 1037ev_idle_stop (struct ev_idle *w)
713{ 1038{
1039 ev_clear_pending ((W)w);
1040 if (ev_is_active (w))
1041 return;
1042
714 idles [w->active - 1] = idles [--idlecnt]; 1043 idles [w->active - 1] = idles [--idlecnt];
715 ev_stop ((W)w); 1044 ev_stop ((W)w);
716} 1045}
717 1046
1047void
1048ev_prepare_start (struct ev_prepare *w)
1049{
1050 if (ev_is_active (w))
1051 return;
1052
1053 ev_start ((W)w, ++preparecnt);
1054 array_needsize (prepares, preparemax, preparecnt, );
1055 prepares [preparecnt - 1] = w;
1056}
1057
1058void
1059ev_prepare_stop (struct ev_prepare *w)
1060{
1061 ev_clear_pending ((W)w);
1062 if (ev_is_active (w))
1063 return;
1064
1065 prepares [w->active - 1] = prepares [--preparecnt];
1066 ev_stop ((W)w);
1067}
1068
1069void
718void evcheck_start (struct ev_check *w) 1070ev_check_start (struct ev_check *w)
719{ 1071{
720 if (ev_is_active (w)) 1072 if (ev_is_active (w))
721 return; 1073 return;
722 1074
723 ev_start ((W)w, ++checkcnt); 1075 ev_start ((W)w, ++checkcnt);
724 array_needsize (checks, checkmax, checkcnt, ); 1076 array_needsize (checks, checkmax, checkcnt, );
725 checks [checkcnt - 1] = w; 1077 checks [checkcnt - 1] = w;
726} 1078}
727 1079
1080void
728void evcheck_stop (struct ev_check *w) 1081ev_check_stop (struct ev_check *w)
729{ 1082{
1083 ev_clear_pending ((W)w);
1084 if (ev_is_active (w))
1085 return;
1086
730 checks [w->active - 1] = checks [--checkcnt]; 1087 checks [w->active - 1] = checks [--checkcnt];
731 ev_stop ((W)w); 1088 ev_stop ((W)w);
732} 1089}
733 1090
1091void
1092ev_child_start (struct ev_child *w)
1093{
1094 if (ev_is_active (w))
1095 return;
1096
1097 ev_start ((W)w, 1);
1098 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1099}
1100
1101void
1102ev_child_stop (struct ev_child *w)
1103{
1104 ev_clear_pending ((W)w);
1105 if (ev_is_active (w))
1106 return;
1107
1108 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1109 ev_stop ((W)w);
1110}
1111
1112/*****************************************************************************/
1113
1114struct ev_once
1115{
1116 struct ev_io io;
1117 struct ev_timer to;
1118 void (*cb)(int revents, void *arg);
1119 void *arg;
1120};
1121
1122static void
1123once_cb (struct ev_once *once, int revents)
1124{
1125 void (*cb)(int revents, void *arg) = once->cb;
1126 void *arg = once->arg;
1127
1128 ev_io_stop (&once->io);
1129 ev_timer_stop (&once->to);
1130 free (once);
1131
1132 cb (revents, arg);
1133}
1134
1135static void
1136once_cb_io (struct ev_io *w, int revents)
1137{
1138 once_cb ((struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)), revents);
1139}
1140
1141static void
1142once_cb_to (struct ev_timer *w, int revents)
1143{
1144 once_cb ((struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)), revents);
1145}
1146
1147void
1148ev_once (int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg)
1149{
1150 struct ev_once *once = malloc (sizeof (struct ev_once));
1151
1152 if (!once)
1153 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg);
1154 else
1155 {
1156 once->cb = cb;
1157 once->arg = arg;
1158
1159 ev_watcher_init (&once->io, once_cb_io);
1160 if (fd >= 0)
1161 {
1162 ev_io_set (&once->io, fd, events);
1163 ev_io_start (&once->io);
1164 }
1165
1166 ev_watcher_init (&once->to, once_cb_to);
1167 if (timeout >= 0.)
1168 {
1169 ev_timer_set (&once->to, timeout, 0.);
1170 ev_timer_start (&once->to);
1171 }
1172 }
1173}
1174
734/*****************************************************************************/ 1175/*****************************************************************************/
735 1176
736#if 0 1177#if 0
737 1178
1179struct ev_io wio;
1180
738static void 1181static void
739sin_cb (struct ev_io *w, int revents) 1182sin_cb (struct ev_io *w, int revents)
740{ 1183{
741 fprintf (stderr, "sin %d, revents %d\n", w->fd, revents); 1184 fprintf (stderr, "sin %d, revents %d\n", w->fd, revents);
742} 1185}
743 1186
744static void 1187static void
745ocb (struct ev_timer *w, int revents) 1188ocb (struct ev_timer *w, int revents)
746{ 1189{
747 //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data); 1190 //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data);
748 evtimer_stop (w); 1191 ev_timer_stop (w);
749 evtimer_start (w); 1192 ev_timer_start (w);
750} 1193}
751 1194
752static void 1195static void
753scb (struct ev_signal *w, int revents) 1196scb (struct ev_signal *w, int revents)
754{ 1197{
755 fprintf (stderr, "signal %x,%d\n", revents, w->signum); 1198 fprintf (stderr, "signal %x,%d\n", revents, w->signum);
1199 ev_io_stop (&wio);
1200 ev_io_start (&wio);
756} 1201}
757 1202
758static void 1203static void
759gcb (struct ev_signal *w, int revents) 1204gcb (struct ev_signal *w, int revents)
760{ 1205{
761 fprintf (stderr, "generic %x\n", revents); 1206 fprintf (stderr, "generic %x\n", revents);
1207
762} 1208}
763 1209
764int main (void) 1210int main (void)
765{ 1211{
766 struct ev_io sin;
767
768 ev_init (0); 1212 ev_init (0);
769 1213
770 evw_init (&sin, sin_cb, 55);
771 evio_set (&sin, 0, EV_READ); 1214 ev_io_init (&wio, sin_cb, 0, EV_READ);
772 evio_start (&sin); 1215 ev_io_start (&wio);
773 1216
774 struct ev_timer t[10000]; 1217 struct ev_timer t[10000];
775 1218
776#if 0 1219#if 0
777 int i; 1220 int i;
778 for (i = 0; i < 10000; ++i) 1221 for (i = 0; i < 10000; ++i)
779 { 1222 {
780 struct ev_timer *w = t + i; 1223 struct ev_timer *w = t + i;
781 evw_init (w, ocb, i); 1224 ev_watcher_init (w, ocb, i);
782 evtimer_set_abs (w, drand48 (), 0.99775533); 1225 ev_timer_init_abs (w, ocb, drand48 (), 0.99775533);
783 evtimer_start (w); 1226 ev_timer_start (w);
784 if (drand48 () < 0.5) 1227 if (drand48 () < 0.5)
785 evtimer_stop (w); 1228 ev_timer_stop (w);
786 } 1229 }
787#endif 1230#endif
788 1231
789 struct ev_timer t1; 1232 struct ev_timer t1;
790 evw_init (&t1, ocb, 0); 1233 ev_timer_init (&t1, ocb, 5, 10);
791 evtimer_set_abs (&t1, 5, 10);
792 evtimer_start (&t1); 1234 ev_timer_start (&t1);
793 1235
794 struct ev_signal sig; 1236 struct ev_signal sig;
795 evw_init (&sig, scb, 65535);
796 evsignal_set (&sig, SIGQUIT); 1237 ev_signal_init (&sig, scb, SIGQUIT);
797 evsignal_start (&sig); 1238 ev_signal_start (&sig);
798 1239
799 struct ev_check cw; 1240 struct ev_check cw;
800 evw_init (&cw, gcb, 0); 1241 ev_check_init (&cw, gcb);
801 evcheck_start (&cw); 1242 ev_check_start (&cw);
802 1243
803 struct ev_idle iw; 1244 struct ev_idle iw;
804 evw_init (&iw, gcb, 0); 1245 ev_idle_init (&iw, gcb);
805 evidle_start (&iw); 1246 ev_idle_start (&iw);
806 1247
807 ev_loop (0); 1248 ev_loop (0);
808 1249
809 return 0; 1250 return 0;
810} 1251}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines