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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines