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

Comparing libev/ev.c (file contents):
Revision 1.27 by root, Wed Oct 31 22:16:36 2007 UTC vs.
Revision 1.49 by root, Sat Nov 3 16:16:58 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines