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

Comparing libev/ev.c (file contents):
Revision 1.52 by root, Sat Nov 3 22:10:39 2007 UTC vs.
Revision 1.69 by root, Tue Nov 6 00:10:04 2007 UTC

28 * (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
29 * 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.
30 */ 30 */
31#ifndef EV_STANDALONE 31#ifndef EV_STANDALONE
32# include "config.h" 32# include "config.h"
33
34# if HAVE_CLOCK_GETTIME
35# define EV_USE_MONOTONIC 1
36# define EV_USE_REALTIME 1
37# endif
38
39# if HAVE_SELECT && HAVE_SYS_SELECT_H
40# define EV_USE_SELECT 1
41# endif
42
43# if HAVE_POLL && HAVE_POLL_H
44# define EV_USE_POLL 1
45# endif
46
47# if HAVE_EPOLL && HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H
48# define EV_USE_EPOLL 1
49# endif
50
51# if HAVE_KQUEUE && HAVE_WORKING_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H
52# define EV_USE_KQUEUE 1
53# endif
54
33#endif 55#endif
34 56
35#include <math.h> 57#include <math.h>
36#include <stdlib.h> 58#include <stdlib.h>
37#include <unistd.h> 59#include <unistd.h>
58 80
59#ifndef EV_USE_SELECT 81#ifndef EV_USE_SELECT
60# define EV_USE_SELECT 1 82# define EV_USE_SELECT 1
61#endif 83#endif
62 84
63#ifndef EV_USEV_POLL 85#ifndef EV_USE_POLL
64# define EV_USEV_POLL 0 /* poll is usually slower than select, and not as well tested */ 86# define EV_USE_POLL 0 /* poll is usually slower than select, and not as well tested */
65#endif 87#endif
66 88
67#ifndef EV_USE_EPOLL 89#ifndef EV_USE_EPOLL
68# define EV_USE_EPOLL 0 90# define EV_USE_EPOLL 0
69#endif 91#endif
70 92
71#ifndef EV_USE_KQUEUE 93#ifndef EV_USE_KQUEUE
72# define EV_USE_KQUEUE 0 94# define EV_USE_KQUEUE 0
95#endif
96
97#ifndef EV_USE_WIN32
98# ifdef WIN32
99# define EV_USE_WIN32 1
100# else
101# define EV_USE_WIN32 0
102# endif
73#endif 103#endif
74 104
75#ifndef EV_USE_REALTIME 105#ifndef EV_USE_REALTIME
76# define EV_USE_REALTIME 1 106# define EV_USE_REALTIME 1
77#endif 107#endif
113 143
114typedef struct ev_watcher *W; 144typedef struct ev_watcher *W;
115typedef struct ev_watcher_list *WL; 145typedef struct ev_watcher_list *WL;
116typedef struct ev_watcher_time *WT; 146typedef struct ev_watcher_time *WT;
117 147
118static ev_tstamp now_floor, mn_now, diff; /* monotonic clock */ 148static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
119static ev_tstamp rt_now;
120static int method;
121 149
122static int have_monotonic; /* runtime */ 150#if WIN32
123 151/* note: the comment below could not be substantiated, but what would I care */
124static ev_tstamp method_fudge; /* stupid epoll-returns-early bug */ 152/* MSDN says this is required to handle SIGFPE */
125static void (*method_modify)(EV_P_ int fd, int oev, int nev); 153volatile double SIGFPE_REQ = 0.0f;
126static void (*method_poll)(EV_P_ ev_tstamp timeout);
127
128static int activecnt; /* number of active events */
129
130#if EV_USE_SELECT
131static unsigned char *vec_ri, *vec_ro, *vec_wi, *vec_wo;
132static int vec_max;
133#endif 154#endif
134 155
135#if EV_USEV_POLL 156/*****************************************************************************/
136static struct pollfd *polls;
137static int pollmax, pollcnt;
138static int *pollidxs; /* maps fds into structure indices */
139static int pollidxmax;
140#endif
141 157
142#if EV_USE_EPOLL 158static void (*syserr_cb)(void);
143static int epoll_fd = -1;
144 159
145static struct epoll_event *events; 160void ev_set_syserr_cb (void (*cb)(void))
146static int eventmax; 161{
147#endif 162 syserr_cb = cb;
163}
148 164
149#if EV_USE_KQUEUE 165static void
150static int kqueue_fd; 166syserr (void)
151static struct kevent *kqueue_changes; 167{
152static int kqueue_changemax, kqueue_changecnt; 168 if (syserr_cb)
153static struct kevent *kqueue_events; 169 syserr_cb ();
154static int kqueue_eventmax; 170 else
171 {
172 perror ("libev");
173 abort ();
174 }
175}
176
177static void *(*alloc)(void *ptr, long size);
178
179void ev_set_allocator (void *(*cb)(void *ptr, long size))
180{
181 alloc = cb;
182}
183
184static void *
185ev_realloc (void *ptr, long size)
186{
187 ptr = alloc ? alloc (ptr, size) : realloc (ptr, size);
188
189 if (!ptr && size)
190 {
191 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size);
192 abort ();
193 }
194
195 return ptr;
196}
197
198#define ev_malloc(size) ev_realloc (0, (size))
199#define ev_free(ptr) ev_realloc ((ptr), 0)
200
201/*****************************************************************************/
202
203typedef struct
204{
205 WL head;
206 unsigned char events;
207 unsigned char reify;
208} ANFD;
209
210typedef struct
211{
212 W w;
213 int events;
214} ANPENDING;
215
216#if EV_MULTIPLICITY
217
218struct ev_loop
219{
220# define VAR(name,decl) decl;
221# include "ev_vars.h"
222};
223# undef VAR
224# include "ev_wrap.h"
225
226#else
227
228# define VAR(name,decl) static decl;
229# include "ev_vars.h"
230# undef VAR
231
155#endif 232#endif
156 233
157/*****************************************************************************/ 234/*****************************************************************************/
158 235
159inline ev_tstamp 236inline ev_tstamp
191 return rt_now; 268 return rt_now;
192} 269}
193 270
194#define array_roundsize(base,n) ((n) | 4 & ~3) 271#define array_roundsize(base,n) ((n) | 4 & ~3)
195 272
196#define array_needsize(base,cur,cnt,init) \ 273#define array_needsize(base,cur,cnt,init) \
197 if (expect_false ((cnt) > cur)) \ 274 if (expect_false ((cnt) > cur)) \
198 { \ 275 { \
199 int newcnt = cur; \ 276 int newcnt = cur; \
200 do \ 277 do \
201 { \ 278 { \
202 newcnt = array_roundsize (base, newcnt << 1); \ 279 newcnt = array_roundsize (base, newcnt << 1); \
203 } \ 280 } \
204 while ((cnt) > newcnt); \ 281 while ((cnt) > newcnt); \
205 \ 282 \
206 base = realloc (base, sizeof (*base) * (newcnt)); \ 283 base = ev_realloc (base, sizeof (*base) * (newcnt)); \
207 init (base + cur, newcnt - cur); \ 284 init (base + cur, newcnt - cur); \
208 cur = newcnt; \ 285 cur = newcnt; \
209 } 286 }
287
288#define array_slim(stem) \
289 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
290 { \
291 stem ## max = array_roundsize (stem ## cnt >> 1); \
292 base = ev_realloc (base, sizeof (*base) * (stem ## max)); \
293 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\
294 }
295
296#define array_free(stem, idx) \
297 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0;
210 298
211/*****************************************************************************/ 299/*****************************************************************************/
212
213typedef struct
214{
215 struct ev_watcher_list *head;
216 unsigned char events;
217 unsigned char reify;
218} ANFD;
219
220static ANFD *anfds;
221static int anfdmax;
222 300
223static void 301static void
224anfds_init (ANFD *base, int count) 302anfds_init (ANFD *base, int count)
225{ 303{
226 while (count--) 304 while (count--)
230 base->reify = 0; 308 base->reify = 0;
231 309
232 ++base; 310 ++base;
233 } 311 }
234} 312}
235
236typedef struct
237{
238 W w;
239 int events;
240} ANPENDING;
241
242static ANPENDING *pendings [NUMPRI];
243static int pendingmax [NUMPRI], pendingcnt [NUMPRI];
244 313
245static void 314static void
246event (EV_P_ W w, int events) 315event (EV_P_ W w, int events)
247{ 316{
248 if (w->pending) 317 if (w->pending)
281 } 350 }
282} 351}
283 352
284/*****************************************************************************/ 353/*****************************************************************************/
285 354
286static int *fdchanges;
287static int fdchangemax, fdchangecnt;
288
289static void 355static void
290fd_reify (EV_P) 356fd_reify (EV_P)
291{ 357{
292 int i; 358 int i;
293 359
302 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) 368 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
303 events |= w->events; 369 events |= w->events;
304 370
305 anfd->reify = 0; 371 anfd->reify = 0;
306 372
307 if (anfd->events != events)
308 {
309 method_modify (EV_A_ fd, anfd->events, events); 373 method_modify (EV_A_ fd, anfd->events, events);
310 anfd->events = events; 374 anfd->events = events;
311 }
312 } 375 }
313 376
314 fdchangecnt = 0; 377 fdchangecnt = 0;
315} 378}
316 379
353 416
354/* called on ENOMEM in select/poll to kill some fds and retry */ 417/* called on ENOMEM in select/poll to kill some fds and retry */
355static void 418static void
356fd_enomem (EV_P) 419fd_enomem (EV_P)
357{ 420{
358 int fd = anfdmax; 421 int fd;
359 422
360 while (fd--) 423 for (fd = anfdmax; fd--; )
361 if (anfds [fd].events) 424 if (anfds [fd].events)
362 { 425 {
363 close (fd);
364 fd_kill (EV_A_ fd); 426 fd_kill (EV_A_ fd);
365 return; 427 return;
366 } 428 }
367} 429}
368 430
431/* susually called after fork if method needs to re-arm all fds from scratch */
432static void
433fd_rearm_all (EV_P)
434{
435 int fd;
436
437 /* this should be highly optimised to not do anything but set a flag */
438 for (fd = 0; fd < anfdmax; ++fd)
439 if (anfds [fd].events)
440 {
441 anfds [fd].events = 0;
442 fd_change (EV_A_ fd);
443 }
444}
445
369/*****************************************************************************/ 446/*****************************************************************************/
370 447
371static struct ev_timer **timers;
372static int timermax, timercnt;
373
374static struct ev_periodic **periodics;
375static int periodicmax, periodiccnt;
376
377static void 448static void
378upheap (WT *timers, int k) 449upheap (WT *heap, int k)
379{ 450{
380 WT w = timers [k]; 451 WT w = heap [k];
381 452
382 while (k && timers [k >> 1]->at > w->at) 453 while (k && heap [k >> 1]->at > w->at)
383 { 454 {
384 timers [k] = timers [k >> 1]; 455 heap [k] = heap [k >> 1];
385 timers [k]->active = k + 1; 456 ((W)heap [k])->active = k + 1;
386 k >>= 1; 457 k >>= 1;
387 } 458 }
388 459
389 timers [k] = w; 460 heap [k] = w;
390 timers [k]->active = k + 1; 461 ((W)heap [k])->active = k + 1;
391 462
392} 463}
393 464
394static void 465static void
395downheap (WT *timers, int N, int k) 466downheap (WT *heap, int N, int k)
396{ 467{
397 WT w = timers [k]; 468 WT w = heap [k];
398 469
399 while (k < (N >> 1)) 470 while (k < (N >> 1))
400 { 471 {
401 int j = k << 1; 472 int j = k << 1;
402 473
403 if (j + 1 < N && timers [j]->at > timers [j + 1]->at) 474 if (j + 1 < N && heap [j]->at > heap [j + 1]->at)
404 ++j; 475 ++j;
405 476
406 if (w->at <= timers [j]->at) 477 if (w->at <= heap [j]->at)
407 break; 478 break;
408 479
409 timers [k] = timers [j]; 480 heap [k] = heap [j];
410 timers [k]->active = k + 1; 481 ((W)heap [k])->active = k + 1;
411 k = j; 482 k = j;
412 } 483 }
413 484
414 timers [k] = w; 485 heap [k] = w;
415 timers [k]->active = k + 1; 486 ((W)heap [k])->active = k + 1;
416} 487}
417 488
418/*****************************************************************************/ 489/*****************************************************************************/
419 490
420typedef struct 491typedef struct
421{ 492{
422 struct ev_watcher_list *head; 493 WL head;
423 sig_atomic_t volatile gotsig; 494 sig_atomic_t volatile gotsig;
424} ANSIG; 495} ANSIG;
425 496
426static ANSIG *signals; 497static ANSIG *signals;
427static int signalmax; 498static int signalmax;
443} 514}
444 515
445static void 516static void
446sighandler (int signum) 517sighandler (int signum)
447{ 518{
519#if WIN32
520 signal (signum, sighandler);
521#endif
522
448 signals [signum - 1].gotsig = 1; 523 signals [signum - 1].gotsig = 1;
449 524
450 if (!gotsig) 525 if (!gotsig)
451 { 526 {
452 int old_errno = errno; 527 int old_errno = errno;
457} 532}
458 533
459static void 534static void
460sigcb (EV_P_ struct ev_io *iow, int revents) 535sigcb (EV_P_ struct ev_io *iow, int revents)
461{ 536{
462 struct ev_watcher_list *w; 537 WL w;
463 int signum; 538 int signum;
464 539
465 read (sigpipe [0], &revents, 1); 540 read (sigpipe [0], &revents, 1);
466 gotsig = 0; 541 gotsig = 0;
467 542
486 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK); 561 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK);
487 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); 562 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK);
488#endif 563#endif
489 564
490 ev_io_set (&sigev, sigpipe [0], EV_READ); 565 ev_io_set (&sigev, sigpipe [0], EV_READ);
491 ev_io_start (&sigev); 566 ev_io_start (EV_A_ &sigev);
492 ev_unref (EV_A); /* child watcher should not keep loop alive */ 567 ev_unref (EV_A); /* child watcher should not keep loop alive */
493} 568}
494 569
495/*****************************************************************************/ 570/*****************************************************************************/
496 571
497static struct ev_idle **idles; 572#ifndef WIN32
498static int idlemax, idlecnt;
499
500static struct ev_prepare **prepares;
501static int preparemax, preparecnt;
502
503static struct ev_check **checks;
504static int checkmax, checkcnt;
505
506/*****************************************************************************/
507 573
508static struct ev_child *childs [PID_HASHSIZE]; 574static struct ev_child *childs [PID_HASHSIZE];
509static struct ev_signal childev; 575static struct ev_signal childev;
510
511#ifndef WIN32
512 576
513#ifndef WCONTINUED 577#ifndef WCONTINUED
514# define WCONTINUED 0 578# define WCONTINUED 0
515#endif 579#endif
516 580
520 struct ev_child *w; 584 struct ev_child *w;
521 585
522 for (w = (struct ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (struct ev_child *)((WL)w)->next) 586 for (w = (struct ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (struct ev_child *)((WL)w)->next)
523 if (w->pid == pid || !w->pid) 587 if (w->pid == pid || !w->pid)
524 { 588 {
525 w->priority = sw->priority; /* need to do it *now* */ 589 ev_priority (w) = ev_priority (sw); /* need to do it *now* */
526 w->rpid = pid; 590 w->rpid = pid;
527 w->rstatus = status; 591 w->rstatus = status;
528 event (EV_A_ (W)w, EV_CHILD); 592 event (EV_A_ (W)w, EV_CHILD);
529 } 593 }
530} 594}
531 595
532static void 596static void
552# include "ev_kqueue.c" 616# include "ev_kqueue.c"
553#endif 617#endif
554#if EV_USE_EPOLL 618#if EV_USE_EPOLL
555# include "ev_epoll.c" 619# include "ev_epoll.c"
556#endif 620#endif
557#if EV_USEV_POLL 621#if EV_USE_POLL
558# include "ev_poll.c" 622# include "ev_poll.c"
559#endif 623#endif
560#if EV_USE_SELECT 624#if EV_USE_SELECT
561# include "ev_select.c" 625# include "ev_select.c"
562#endif 626#endif
589ev_method (EV_P) 653ev_method (EV_P)
590{ 654{
591 return method; 655 return method;
592} 656}
593 657
594int 658static void
595ev_init (EV_P_ int methods) 659loop_init (EV_P_ int methods)
596{ 660{
597 if (!method) 661 if (!method)
598 { 662 {
599#if EV_USE_MONOTONIC 663#if EV_USE_MONOTONIC
600 { 664 {
605#endif 669#endif
606 670
607 rt_now = ev_time (); 671 rt_now = ev_time ();
608 mn_now = get_clock (); 672 mn_now = get_clock ();
609 now_floor = mn_now; 673 now_floor = mn_now;
610 diff = rt_now - mn_now; 674 rtmn_diff = rt_now - mn_now;
611
612 if (pipe (sigpipe))
613 return 0;
614 675
615 if (methods == EVMETHOD_AUTO) 676 if (methods == EVMETHOD_AUTO)
616 if (!enable_secure () && getenv ("LIBmethodS")) 677 if (!enable_secure () && getenv ("LIBEV_METHODS"))
617 methods = atoi (getenv ("LIBmethodS")); 678 methods = atoi (getenv ("LIBEV_METHODS"));
618 else 679 else
619 methods = EVMETHOD_ANY; 680 methods = EVMETHOD_ANY;
620 681
621 method = 0; 682 method = 0;
683#if EV_USE_WIN32
684 if (!method && (methods & EVMETHOD_WIN32 )) method = win32_init (EV_A_ methods);
685#endif
622#if EV_USE_KQUEUE 686#if EV_USE_KQUEUE
623 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); 687 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods);
624#endif 688#endif
625#if EV_USE_EPOLL 689#if EV_USE_EPOLL
626 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); 690 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods);
627#endif 691#endif
628#if EV_USEV_POLL 692#if EV_USE_POLL
629 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); 693 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods);
630#endif 694#endif
631#if EV_USE_SELECT 695#if EV_USE_SELECT
632 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 696 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods);
633#endif 697#endif
698 }
699}
634 700
701void
702loop_destroy (EV_P)
703{
704 int i;
705
706#if EV_USE_WIN32
707 if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A);
708#endif
709#if EV_USE_KQUEUE
710 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
711#endif
712#if EV_USE_EPOLL
713 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A);
714#endif
715#if EV_USE_POLL
716 if (method == EVMETHOD_POLL ) poll_destroy (EV_A);
717#endif
718#if EV_USE_SELECT
719 if (method == EVMETHOD_SELECT) select_destroy (EV_A);
720#endif
721
722 for (i = NUMPRI; i--; )
723 array_free (pending, [i]);
724
725 array_free (fdchange, );
726 array_free (timer, );
727 array_free (periodic, );
728 array_free (idle, );
729 array_free (prepare, );
730 array_free (check, );
731
732 method = 0;
733 /*TODO*/
734}
735
736void
737loop_fork (EV_P)
738{
739 /*TODO*/
740#if EV_USE_EPOLL
741 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A);
742#endif
743#if EV_USE_KQUEUE
744 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
745#endif
746}
747
748#if EV_MULTIPLICITY
749struct ev_loop *
750ev_loop_new (int methods)
751{
752 struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
753
754 memset (loop, 0, sizeof (struct ev_loop));
755
756 loop_init (EV_A_ methods);
757
758 if (ev_method (EV_A))
759 return loop;
760
761 return 0;
762}
763
764void
765ev_loop_destroy (EV_P)
766{
767 loop_destroy (EV_A);
768 ev_free (loop);
769}
770
771void
772ev_loop_fork (EV_P)
773{
774 loop_fork (EV_A);
775}
776
777#endif
778
779#if EV_MULTIPLICITY
780struct ev_loop default_loop_struct;
781static struct ev_loop *default_loop;
782
783struct ev_loop *
784#else
785static int default_loop;
786
787int
788#endif
789ev_default_loop (int methods)
790{
791 if (sigpipe [0] == sigpipe [1])
792 if (pipe (sigpipe))
793 return 0;
794
795 if (!default_loop)
796 {
797#if EV_MULTIPLICITY
798 struct ev_loop *loop = default_loop = &default_loop_struct;
799#else
800 default_loop = 1;
801#endif
802
803 loop_init (EV_A_ methods);
804
635 if (method) 805 if (ev_method (EV_A))
636 { 806 {
637 ev_watcher_init (&sigev, sigcb); 807 ev_watcher_init (&sigev, sigcb);
638 ev_set_priority (&sigev, EV_MAXPRI); 808 ev_set_priority (&sigev, EV_MAXPRI);
639 siginit (EV_A); 809 siginit (EV_A);
640 810
643 ev_set_priority (&childev, EV_MAXPRI); 813 ev_set_priority (&childev, EV_MAXPRI);
644 ev_signal_start (EV_A_ &childev); 814 ev_signal_start (EV_A_ &childev);
645 ev_unref (EV_A); /* child watcher should not keep loop alive */ 815 ev_unref (EV_A); /* child watcher should not keep loop alive */
646#endif 816#endif
647 } 817 }
818 else
819 default_loop = 0;
648 } 820 }
649 821
650 return method; 822 return default_loop;
651} 823}
652 824
653/*****************************************************************************/
654
655void 825void
656ev_fork_prepare (void) 826ev_default_destroy (void)
657{ 827{
658 /* nop */ 828#if EV_MULTIPLICITY
659} 829 struct ev_loop *loop = default_loop;
660
661void
662ev_fork_parent (void)
663{
664 /* nop */
665}
666
667void
668ev_fork_child (void)
669{
670#if EV_USE_EPOLL
671 if (method == EVMETHOD_EPOLL)
672 epoll_postfork_child ();
673#endif 830#endif
674 831
832 ev_ref (EV_A); /* child watcher */
833 ev_signal_stop (EV_A_ &childev);
834
835 ev_ref (EV_A); /* signal watcher */
675 ev_io_stop (&sigev); 836 ev_io_stop (EV_A_ &sigev);
837
838 close (sigpipe [0]); sigpipe [0] = 0;
839 close (sigpipe [1]); sigpipe [1] = 0;
840
841 loop_destroy (EV_A);
842}
843
844void
845ev_default_fork (void)
846{
847#if EV_MULTIPLICITY
848 struct ev_loop *loop = default_loop;
849#endif
850
851 loop_fork (EV_A);
852
853 ev_io_stop (EV_A_ &sigev);
676 close (sigpipe [0]); 854 close (sigpipe [0]);
677 close (sigpipe [1]); 855 close (sigpipe [1]);
678 pipe (sigpipe); 856 pipe (sigpipe);
857
858 ev_ref (EV_A); /* signal watcher */
679 siginit (); 859 siginit (EV_A);
680} 860}
681 861
682/*****************************************************************************/ 862/*****************************************************************************/
683 863
684static void 864static void
700} 880}
701 881
702static void 882static void
703timers_reify (EV_P) 883timers_reify (EV_P)
704{ 884{
705 while (timercnt && timers [0]->at <= mn_now) 885 while (timercnt && ((WT)timers [0])->at <= mn_now)
706 { 886 {
707 struct ev_timer *w = timers [0]; 887 struct ev_timer *w = timers [0];
888
889 assert (("inactive timer on timer heap detected", ev_is_active (w)));
708 890
709 /* first reschedule or stop timer */ 891 /* first reschedule or stop timer */
710 if (w->repeat) 892 if (w->repeat)
711 { 893 {
712 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); 894 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.));
713 w->at = mn_now + w->repeat; 895 ((WT)w)->at = mn_now + w->repeat;
714 downheap ((WT *)timers, timercnt, 0); 896 downheap ((WT *)timers, timercnt, 0);
715 } 897 }
716 else 898 else
717 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ 899 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
718 900
719 event ((W)w, EV_TIMEOUT); 901 event (EV_A_ (W)w, EV_TIMEOUT);
720 } 902 }
721} 903}
722 904
723static void 905static void
724periodics_reify (EV_P) 906periodics_reify (EV_P)
725{ 907{
726 while (periodiccnt && periodics [0]->at <= rt_now) 908 while (periodiccnt && ((WT)periodics [0])->at <= rt_now)
727 { 909 {
728 struct ev_periodic *w = periodics [0]; 910 struct ev_periodic *w = periodics [0];
911
912 assert (("inactive timer on periodic heap detected", ev_is_active (w)));
729 913
730 /* first reschedule or stop timer */ 914 /* first reschedule or stop timer */
731 if (w->interval) 915 if (w->interval)
732 { 916 {
733 w->at += floor ((rt_now - w->at) / w->interval + 1.) * w->interval; 917 ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval;
734 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", w->at > rt_now)); 918 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now));
735 downheap ((WT *)periodics, periodiccnt, 0); 919 downheap ((WT *)periodics, periodiccnt, 0);
736 } 920 }
737 else 921 else
738 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ 922 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
739 923
740 event (EV_A_ (W)w, EV_PERIODIC); 924 event (EV_A_ (W)w, EV_PERIODIC);
741 } 925 }
742} 926}
743 927
744static void 928static void
745periodics_reschedule (EV_P_ ev_tstamp diff) 929periodics_reschedule (EV_P)
746{ 930{
747 int i; 931 int i;
748 932
749 /* adjust periodics after time jump */ 933 /* adjust periodics after time jump */
750 for (i = 0; i < periodiccnt; ++i) 934 for (i = 0; i < periodiccnt; ++i)
751 { 935 {
752 struct ev_periodic *w = periodics [i]; 936 struct ev_periodic *w = periodics [i];
753 937
754 if (w->interval) 938 if (w->interval)
755 { 939 {
756 ev_tstamp diff = ceil ((rt_now - w->at) / w->interval) * w->interval; 940 ev_tstamp diff = ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval;
757 941
758 if (fabs (diff) >= 1e-4) 942 if (fabs (diff) >= 1e-4)
759 { 943 {
760 ev_periodic_stop (EV_A_ w); 944 ev_periodic_stop (EV_A_ w);
761 ev_periodic_start (EV_A_ w); 945 ev_periodic_start (EV_A_ w);
771{ 955{
772 mn_now = get_clock (); 956 mn_now = get_clock ();
773 957
774 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5)) 958 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5))
775 { 959 {
776 rt_now = mn_now + diff; 960 rt_now = rtmn_diff + mn_now;
777 return 0; 961 return 0;
778 } 962 }
779 else 963 else
780 { 964 {
781 now_floor = mn_now; 965 now_floor = mn_now;
792#if EV_USE_MONOTONIC 976#if EV_USE_MONOTONIC
793 if (expect_true (have_monotonic)) 977 if (expect_true (have_monotonic))
794 { 978 {
795 if (time_update_monotonic (EV_A)) 979 if (time_update_monotonic (EV_A))
796 { 980 {
797 ev_tstamp odiff = diff; 981 ev_tstamp odiff = rtmn_diff;
798 982
799 for (i = 4; --i; ) /* loop a few times, before making important decisions */ 983 for (i = 4; --i; ) /* loop a few times, before making important decisions */
800 { 984 {
801 diff = rt_now - mn_now; 985 rtmn_diff = rt_now - mn_now;
802 986
803 if (fabs (odiff - diff) < MIN_TIMEJUMP) 987 if (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP)
804 return; /* all is well */ 988 return; /* all is well */
805 989
806 rt_now = ev_time (); 990 rt_now = ev_time ();
807 mn_now = get_clock (); 991 mn_now = get_clock ();
808 now_floor = mn_now; 992 now_floor = mn_now;
809 } 993 }
810 994
811 periodics_reschedule (EV_A_ diff - odiff); 995 periodics_reschedule (EV_A);
812 /* no timer adjustment, as the monotonic clock doesn't jump */ 996 /* no timer adjustment, as the monotonic clock doesn't jump */
997 /* timers_reschedule (EV_A_ rtmn_diff - odiff) */
813 } 998 }
814 } 999 }
815 else 1000 else
816#endif 1001#endif
817 { 1002 {
818 rt_now = ev_time (); 1003 rt_now = ev_time ();
819 1004
820 if (expect_false (mn_now > rt_now || mn_now < rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP)) 1005 if (expect_false (mn_now > rt_now || mn_now < rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP))
821 { 1006 {
822 periodics_reschedule (EV_A_ rt_now - mn_now); 1007 periodics_reschedule (EV_A);
823 1008
824 /* adjust timers. this is easy, as the offset is the same for all */ 1009 /* adjust timers. this is easy, as the offset is the same for all */
825 for (i = 0; i < timercnt; ++i) 1010 for (i = 0; i < timercnt; ++i)
826 timers [i]->at += diff; 1011 ((WT)timers [i])->at += rt_now - mn_now;
827 } 1012 }
828 1013
829 mn_now = rt_now; 1014 mn_now = rt_now;
830 } 1015 }
831} 1016}
882 { 1067 {
883 block = MAX_BLOCKTIME; 1068 block = MAX_BLOCKTIME;
884 1069
885 if (timercnt) 1070 if (timercnt)
886 { 1071 {
887 ev_tstamp to = timers [0]->at - mn_now + method_fudge; 1072 ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge;
888 if (block > to) block = to; 1073 if (block > to) block = to;
889 } 1074 }
890 1075
891 if (periodiccnt) 1076 if (periodiccnt)
892 { 1077 {
893 ev_tstamp to = periodics [0]->at - rt_now + method_fudge; 1078 ev_tstamp to = ((WT)periodics [0])->at - rt_now + method_fudge;
894 if (block > to) block = to; 1079 if (block > to) block = to;
895 } 1080 }
896 1081
897 if (block < 0.) block = 0.; 1082 if (block < 0.) block = 0.;
898 } 1083 }
1015ev_timer_start (EV_P_ struct ev_timer *w) 1200ev_timer_start (EV_P_ struct ev_timer *w)
1016{ 1201{
1017 if (ev_is_active (w)) 1202 if (ev_is_active (w))
1018 return; 1203 return;
1019 1204
1020 w->at += mn_now; 1205 ((WT)w)->at += mn_now;
1021 1206
1022 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1207 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1023 1208
1024 ev_start (EV_A_ (W)w, ++timercnt); 1209 ev_start (EV_A_ (W)w, ++timercnt);
1025 array_needsize (timers, timermax, timercnt, ); 1210 array_needsize (timers, timermax, timercnt, );
1026 timers [timercnt - 1] = w; 1211 timers [timercnt - 1] = w;
1027 upheap ((WT *)timers, timercnt - 1); 1212 upheap ((WT *)timers, timercnt - 1);
1213
1214 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1028} 1215}
1029 1216
1030void 1217void
1031ev_timer_stop (EV_P_ struct ev_timer *w) 1218ev_timer_stop (EV_P_ struct ev_timer *w)
1032{ 1219{
1033 ev_clear_pending (EV_A_ (W)w); 1220 ev_clear_pending (EV_A_ (W)w);
1034 if (!ev_is_active (w)) 1221 if (!ev_is_active (w))
1035 return; 1222 return;
1036 1223
1224 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1225
1037 if (w->active < timercnt--) 1226 if (((W)w)->active < timercnt--)
1038 { 1227 {
1039 timers [w->active - 1] = timers [timercnt]; 1228 timers [((W)w)->active - 1] = timers [timercnt];
1040 downheap ((WT *)timers, timercnt, w->active - 1); 1229 downheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1041 } 1230 }
1042 1231
1043 w->at = w->repeat; 1232 ((WT)w)->at = w->repeat;
1044 1233
1045 ev_stop (EV_A_ (W)w); 1234 ev_stop (EV_A_ (W)w);
1046} 1235}
1047 1236
1048void 1237void
1050{ 1239{
1051 if (ev_is_active (w)) 1240 if (ev_is_active (w))
1052 { 1241 {
1053 if (w->repeat) 1242 if (w->repeat)
1054 { 1243 {
1055 w->at = mn_now + w->repeat; 1244 ((WT)w)->at = mn_now + w->repeat;
1056 downheap ((WT *)timers, timercnt, w->active - 1); 1245 downheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1057 } 1246 }
1058 else 1247 else
1059 ev_timer_stop (EV_A_ w); 1248 ev_timer_stop (EV_A_ w);
1060 } 1249 }
1061 else if (w->repeat) 1250 else if (w->repeat)
1070 1259
1071 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); 1260 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.));
1072 1261
1073 /* this formula differs from the one in periodic_reify because we do not always round up */ 1262 /* this formula differs from the one in periodic_reify because we do not always round up */
1074 if (w->interval) 1263 if (w->interval)
1075 w->at += ceil ((rt_now - w->at) / w->interval) * w->interval; 1264 ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval;
1076 1265
1077 ev_start (EV_A_ (W)w, ++periodiccnt); 1266 ev_start (EV_A_ (W)w, ++periodiccnt);
1078 array_needsize (periodics, periodicmax, periodiccnt, ); 1267 array_needsize (periodics, periodicmax, periodiccnt, );
1079 periodics [periodiccnt - 1] = w; 1268 periodics [periodiccnt - 1] = w;
1080 upheap ((WT *)periodics, periodiccnt - 1); 1269 upheap ((WT *)periodics, periodiccnt - 1);
1270
1271 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1081} 1272}
1082 1273
1083void 1274void
1084ev_periodic_stop (EV_P_ struct ev_periodic *w) 1275ev_periodic_stop (EV_P_ struct ev_periodic *w)
1085{ 1276{
1086 ev_clear_pending (EV_A_ (W)w); 1277 ev_clear_pending (EV_A_ (W)w);
1087 if (!ev_is_active (w)) 1278 if (!ev_is_active (w))
1088 return; 1279 return;
1089 1280
1281 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1282
1090 if (w->active < periodiccnt--) 1283 if (((W)w)->active < periodiccnt--)
1091 { 1284 {
1092 periodics [w->active - 1] = periodics [periodiccnt]; 1285 periodics [((W)w)->active - 1] = periodics [periodiccnt];
1093 downheap ((WT *)periodics, periodiccnt, w->active - 1); 1286 downheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1);
1094 } 1287 }
1095 1288
1289 ev_stop (EV_A_ (W)w);
1290}
1291
1292void
1293ev_idle_start (EV_P_ struct ev_idle *w)
1294{
1295 if (ev_is_active (w))
1296 return;
1297
1298 ev_start (EV_A_ (W)w, ++idlecnt);
1299 array_needsize (idles, idlemax, idlecnt, );
1300 idles [idlecnt - 1] = w;
1301}
1302
1303void
1304ev_idle_stop (EV_P_ struct ev_idle *w)
1305{
1306 ev_clear_pending (EV_A_ (W)w);
1307 if (ev_is_active (w))
1308 return;
1309
1310 idles [((W)w)->active - 1] = idles [--idlecnt];
1311 ev_stop (EV_A_ (W)w);
1312}
1313
1314void
1315ev_prepare_start (EV_P_ struct ev_prepare *w)
1316{
1317 if (ev_is_active (w))
1318 return;
1319
1320 ev_start (EV_A_ (W)w, ++preparecnt);
1321 array_needsize (prepares, preparemax, preparecnt, );
1322 prepares [preparecnt - 1] = w;
1323}
1324
1325void
1326ev_prepare_stop (EV_P_ struct ev_prepare *w)
1327{
1328 ev_clear_pending (EV_A_ (W)w);
1329 if (ev_is_active (w))
1330 return;
1331
1332 prepares [((W)w)->active - 1] = prepares [--preparecnt];
1333 ev_stop (EV_A_ (W)w);
1334}
1335
1336void
1337ev_check_start (EV_P_ struct ev_check *w)
1338{
1339 if (ev_is_active (w))
1340 return;
1341
1342 ev_start (EV_A_ (W)w, ++checkcnt);
1343 array_needsize (checks, checkmax, checkcnt, );
1344 checks [checkcnt - 1] = w;
1345}
1346
1347void
1348ev_check_stop (EV_P_ struct ev_check *w)
1349{
1350 ev_clear_pending (EV_A_ (W)w);
1351 if (ev_is_active (w))
1352 return;
1353
1354 checks [((W)w)->active - 1] = checks [--checkcnt];
1096 ev_stop (EV_A_ (W)w); 1355 ev_stop (EV_A_ (W)w);
1097} 1356}
1098 1357
1099#ifndef SA_RESTART 1358#ifndef SA_RESTART
1100# define SA_RESTART 0 1359# define SA_RESTART 0
1101#endif 1360#endif
1102 1361
1103void 1362void
1104ev_signal_start (EV_P_ struct ev_signal *w) 1363ev_signal_start (EV_P_ struct ev_signal *w)
1105{ 1364{
1365#if EV_MULTIPLICITY
1366 assert (("signal watchers are only supported in the default loop", loop == default_loop));
1367#endif
1106 if (ev_is_active (w)) 1368 if (ev_is_active (w))
1107 return; 1369 return;
1108 1370
1109 assert (("ev_signal_start called with illegal signal number", w->signum > 0)); 1371 assert (("ev_signal_start called with illegal signal number", w->signum > 0));
1110 1372
1111 ev_start (EV_A_ (W)w, 1); 1373 ev_start (EV_A_ (W)w, 1);
1112 array_needsize (signals, signalmax, w->signum, signals_init); 1374 array_needsize (signals, signalmax, w->signum, signals_init);
1113 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1375 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1114 1376
1115 if (!w->next) 1377 if (!((WL)w)->next)
1116 { 1378 {
1379#if WIN32
1380 signal (w->signum, sighandler);
1381#else
1117 struct sigaction sa; 1382 struct sigaction sa;
1118 sa.sa_handler = sighandler; 1383 sa.sa_handler = sighandler;
1119 sigfillset (&sa.sa_mask); 1384 sigfillset (&sa.sa_mask);
1120 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ 1385 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */
1121 sigaction (w->signum, &sa, 0); 1386 sigaction (w->signum, &sa, 0);
1387#endif
1122 } 1388 }
1123} 1389}
1124 1390
1125void 1391void
1126ev_signal_stop (EV_P_ struct ev_signal *w) 1392ev_signal_stop (EV_P_ struct ev_signal *w)
1135 if (!signals [w->signum - 1].head) 1401 if (!signals [w->signum - 1].head)
1136 signal (w->signum, SIG_DFL); 1402 signal (w->signum, SIG_DFL);
1137} 1403}
1138 1404
1139void 1405void
1140ev_idle_start (EV_P_ struct ev_idle *w)
1141{
1142 if (ev_is_active (w))
1143 return;
1144
1145 ev_start (EV_A_ (W)w, ++idlecnt);
1146 array_needsize (idles, idlemax, idlecnt, );
1147 idles [idlecnt - 1] = w;
1148}
1149
1150void
1151ev_idle_stop (EV_P_ struct ev_idle *w)
1152{
1153 ev_clear_pending (EV_A_ (W)w);
1154 if (ev_is_active (w))
1155 return;
1156
1157 idles [w->active - 1] = idles [--idlecnt];
1158 ev_stop (EV_A_ (W)w);
1159}
1160
1161void
1162ev_prepare_start (EV_P_ struct ev_prepare *w)
1163{
1164 if (ev_is_active (w))
1165 return;
1166
1167 ev_start (EV_A_ (W)w, ++preparecnt);
1168 array_needsize (prepares, preparemax, preparecnt, );
1169 prepares [preparecnt - 1] = w;
1170}
1171
1172void
1173ev_prepare_stop (EV_P_ struct ev_prepare *w)
1174{
1175 ev_clear_pending (EV_A_ (W)w);
1176 if (ev_is_active (w))
1177 return;
1178
1179 prepares [w->active - 1] = prepares [--preparecnt];
1180 ev_stop (EV_A_ (W)w);
1181}
1182
1183void
1184ev_check_start (EV_P_ struct ev_check *w)
1185{
1186 if (ev_is_active (w))
1187 return;
1188
1189 ev_start (EV_A_ (W)w, ++checkcnt);
1190 array_needsize (checks, checkmax, checkcnt, );
1191 checks [checkcnt - 1] = w;
1192}
1193
1194void
1195ev_check_stop (EV_P_ struct ev_check *w)
1196{
1197 ev_clear_pending (EV_A_ (W)w);
1198 if (ev_is_active (w))
1199 return;
1200
1201 checks [w->active - 1] = checks [--checkcnt];
1202 ev_stop (EV_A_ (W)w);
1203}
1204
1205void
1206ev_child_start (EV_P_ struct ev_child *w) 1406ev_child_start (EV_P_ struct ev_child *w)
1207{ 1407{
1408#if EV_MULTIPLICITY
1409 assert (("child watchers are only supported in the default loop", loop == default_loop));
1410#endif
1208 if (ev_is_active (w)) 1411 if (ev_is_active (w))
1209 return; 1412 return;
1210 1413
1211 ev_start (EV_A_ (W)w, 1); 1414 ev_start (EV_A_ (W)w, 1);
1212 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1415 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1239 void (*cb)(int revents, void *arg) = once->cb; 1442 void (*cb)(int revents, void *arg) = once->cb;
1240 void *arg = once->arg; 1443 void *arg = once->arg;
1241 1444
1242 ev_io_stop (EV_A_ &once->io); 1445 ev_io_stop (EV_A_ &once->io);
1243 ev_timer_stop (EV_A_ &once->to); 1446 ev_timer_stop (EV_A_ &once->to);
1244 free (once); 1447 ev_free (once);
1245 1448
1246 cb (revents, arg); 1449 cb (revents, arg);
1247} 1450}
1248 1451
1249static void 1452static void
1259} 1462}
1260 1463
1261void 1464void
1262ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 1465ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg)
1263{ 1466{
1264 struct ev_once *once = malloc (sizeof (struct ev_once)); 1467 struct ev_once *once = ev_malloc (sizeof (struct ev_once));
1265 1468
1266 if (!once) 1469 if (!once)
1267 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); 1470 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg);
1268 else 1471 else
1269 { 1472 {
1284 ev_timer_start (EV_A_ &once->to); 1487 ev_timer_start (EV_A_ &once->to);
1285 } 1488 }
1286 } 1489 }
1287} 1490}
1288 1491
1289/*****************************************************************************/
1290
1291#if 0
1292
1293struct ev_io wio;
1294
1295static void
1296sin_cb (struct ev_io *w, int revents)
1297{
1298 fprintf (stderr, "sin %d, revents %d\n", w->fd, revents);
1299}
1300
1301static void
1302ocb (struct ev_timer *w, int revents)
1303{
1304 //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data);
1305 ev_timer_stop (w);
1306 ev_timer_start (w);
1307}
1308
1309static void
1310scb (struct ev_signal *w, int revents)
1311{
1312 fprintf (stderr, "signal %x,%d\n", revents, w->signum);
1313 ev_io_stop (&wio);
1314 ev_io_start (&wio);
1315}
1316
1317static void
1318gcb (struct ev_signal *w, int revents)
1319{
1320 fprintf (stderr, "generic %x\n", revents);
1321
1322}
1323
1324int main (void)
1325{
1326 ev_init (0);
1327
1328 ev_io_init (&wio, sin_cb, 0, EV_READ);
1329 ev_io_start (&wio);
1330
1331 struct ev_timer t[10000];
1332
1333#if 0
1334 int i;
1335 for (i = 0; i < 10000; ++i)
1336 {
1337 struct ev_timer *w = t + i;
1338 ev_watcher_init (w, ocb, i);
1339 ev_timer_init_abs (w, ocb, drand48 (), 0.99775533);
1340 ev_timer_start (w);
1341 if (drand48 () < 0.5)
1342 ev_timer_stop (w);
1343 }
1344#endif
1345
1346 struct ev_timer t1;
1347 ev_timer_init (&t1, ocb, 5, 10);
1348 ev_timer_start (&t1);
1349
1350 struct ev_signal sig;
1351 ev_signal_init (&sig, scb, SIGQUIT);
1352 ev_signal_start (&sig);
1353
1354 struct ev_check cw;
1355 ev_check_init (&cw, gcb);
1356 ev_check_start (&cw);
1357
1358 struct ev_idle iw;
1359 ev_idle_init (&iw, gcb);
1360 ev_idle_start (&iw);
1361
1362 ev_loop (0);
1363
1364 return 0;
1365}
1366
1367#endif
1368
1369
1370
1371

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines