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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines