… | |
… | |
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 |
… | |
… | |
202 | base = realloc (base, sizeof (*base) * (newcnt)); \ |
232 | base = realloc (base, sizeof (*base) * (newcnt)); \ |
203 | init (base + cur, newcnt - cur); \ |
233 | init (base + cur, newcnt - cur); \ |
204 | cur = newcnt; \ |
234 | cur = newcnt; \ |
205 | } |
235 | } |
206 | |
236 | |
|
|
237 | #define array_free(stem, idx) \ |
|
|
238 | free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
|
|
239 | |
207 | /*****************************************************************************/ |
240 | /*****************************************************************************/ |
208 | |
241 | |
209 | static void |
242 | static void |
210 | anfds_init (ANFD *base, int count) |
243 | anfds_init (ANFD *base, int count) |
211 | { |
244 | { |
… | |
… | |
276 | for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) |
309 | for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) |
277 | events |= w->events; |
310 | events |= w->events; |
278 | |
311 | |
279 | anfd->reify = 0; |
312 | anfd->reify = 0; |
280 | |
313 | |
281 | if (anfd->events != events) |
|
|
282 | { |
|
|
283 | method_modify (EV_A_ fd, anfd->events, events); |
314 | method_modify (EV_A_ fd, anfd->events, events); |
284 | anfd->events = events; |
315 | anfd->events = events; |
285 | } |
|
|
286 | } |
316 | } |
287 | |
317 | |
288 | fdchangecnt = 0; |
318 | fdchangecnt = 0; |
289 | } |
319 | } |
290 | |
320 | |
… | |
… | |
327 | |
357 | |
328 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
358 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
329 | static void |
359 | static void |
330 | fd_enomem (EV_P) |
360 | fd_enomem (EV_P) |
331 | { |
361 | { |
332 | int fd = anfdmax; |
362 | int fd; |
333 | |
363 | |
334 | while (fd--) |
364 | for (fd = anfdmax; fd--; ) |
335 | if (anfds [fd].events) |
365 | if (anfds [fd].events) |
336 | { |
366 | { |
337 | close (fd); |
367 | close (fd); |
338 | fd_kill (EV_A_ fd); |
368 | fd_kill (EV_A_ fd); |
339 | return; |
369 | return; |
340 | } |
370 | } |
341 | } |
371 | } |
342 | |
372 | |
|
|
373 | /* susually called after fork if method needs to re-arm all fds from scratch */ |
|
|
374 | static void |
|
|
375 | fd_rearm_all (EV_P) |
|
|
376 | { |
|
|
377 | int fd; |
|
|
378 | |
|
|
379 | /* this should be highly optimised to not do anything but set a flag */ |
|
|
380 | for (fd = 0; fd < anfdmax; ++fd) |
|
|
381 | if (anfds [fd].events) |
|
|
382 | { |
|
|
383 | anfds [fd].events = 0; |
|
|
384 | fd_change (EV_A_ fd); |
|
|
385 | } |
|
|
386 | } |
|
|
387 | |
343 | /*****************************************************************************/ |
388 | /*****************************************************************************/ |
344 | |
389 | |
345 | static void |
390 | static void |
346 | upheap (WT *heap, int k) |
391 | upheap (WT *heap, int k) |
347 | { |
392 | { |
348 | WT w = heap [k]; |
393 | WT w = heap [k]; |
349 | |
394 | |
350 | while (k && heap [k >> 1]->at > w->at) |
395 | while (k && heap [k >> 1]->at > w->at) |
351 | { |
396 | { |
352 | heap [k] = heap [k >> 1]; |
397 | heap [k] = heap [k >> 1]; |
353 | heap [k]->active = k + 1; |
398 | ((W)heap [k])->active = k + 1; |
354 | k >>= 1; |
399 | k >>= 1; |
355 | } |
400 | } |
356 | |
401 | |
357 | heap [k] = w; |
402 | heap [k] = w; |
358 | heap [k]->active = k + 1; |
403 | ((W)heap [k])->active = k + 1; |
359 | |
404 | |
360 | } |
405 | } |
361 | |
406 | |
362 | static void |
407 | static void |
363 | downheap (WT *heap, int N, int k) |
408 | downheap (WT *heap, int N, int k) |
… | |
… | |
373 | |
418 | |
374 | if (w->at <= heap [j]->at) |
419 | if (w->at <= heap [j]->at) |
375 | break; |
420 | break; |
376 | |
421 | |
377 | heap [k] = heap [j]; |
422 | heap [k] = heap [j]; |
378 | heap [k]->active = k + 1; |
423 | ((W)heap [k])->active = k + 1; |
379 | k = j; |
424 | k = j; |
380 | } |
425 | } |
381 | |
426 | |
382 | heap [k] = w; |
427 | heap [k] = w; |
383 | heap [k]->active = k + 1; |
428 | ((W)heap [k])->active = k + 1; |
384 | } |
429 | } |
385 | |
430 | |
386 | /*****************************************************************************/ |
431 | /*****************************************************************************/ |
387 | |
432 | |
388 | typedef struct |
433 | typedef struct |
… | |
… | |
394 | static ANSIG *signals; |
439 | static ANSIG *signals; |
395 | static int signalmax; |
440 | static int signalmax; |
396 | |
441 | |
397 | static int sigpipe [2]; |
442 | static int sigpipe [2]; |
398 | static sig_atomic_t volatile gotsig; |
443 | static sig_atomic_t volatile gotsig; |
|
|
444 | static struct ev_io sigev; |
399 | |
445 | |
400 | static void |
446 | static void |
401 | signals_init (ANSIG *base, int count) |
447 | signals_init (ANSIG *base, int count) |
402 | { |
448 | { |
403 | while (count--) |
449 | while (count--) |
… | |
… | |
461 | |
507 | |
462 | /*****************************************************************************/ |
508 | /*****************************************************************************/ |
463 | |
509 | |
464 | #ifndef WIN32 |
510 | #ifndef WIN32 |
465 | |
511 | |
|
|
512 | static struct ev_child *childs [PID_HASHSIZE]; |
|
|
513 | static struct ev_signal childev; |
|
|
514 | |
466 | #ifndef WCONTINUED |
515 | #ifndef WCONTINUED |
467 | # define WCONTINUED 0 |
516 | # define WCONTINUED 0 |
468 | #endif |
517 | #endif |
469 | |
518 | |
470 | static void |
519 | static void |
… | |
… | |
473 | struct ev_child *w; |
522 | struct ev_child *w; |
474 | |
523 | |
475 | for (w = (struct ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (struct ev_child *)((WL)w)->next) |
524 | for (w = (struct ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (struct ev_child *)((WL)w)->next) |
476 | if (w->pid == pid || !w->pid) |
525 | if (w->pid == pid || !w->pid) |
477 | { |
526 | { |
478 | w->priority = sw->priority; /* need to do it *now* */ |
527 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
479 | w->rpid = pid; |
528 | w->rpid = pid; |
480 | w->rstatus = status; |
529 | w->rstatus = status; |
481 | event (EV_A_ (W)w, EV_CHILD); |
530 | event (EV_A_ (W)w, EV_CHILD); |
482 | } |
531 | } |
483 | } |
532 | } |
484 | |
533 | |
485 | static void |
534 | static void |
… | |
… | |
505 | # include "ev_kqueue.c" |
554 | # include "ev_kqueue.c" |
506 | #endif |
555 | #endif |
507 | #if EV_USE_EPOLL |
556 | #if EV_USE_EPOLL |
508 | # include "ev_epoll.c" |
557 | # include "ev_epoll.c" |
509 | #endif |
558 | #endif |
510 | #if EV_USEV_POLL |
559 | #if EV_USE_POLL |
511 | # include "ev_poll.c" |
560 | # include "ev_poll.c" |
512 | #endif |
561 | #endif |
513 | #if EV_USE_SELECT |
562 | #if EV_USE_SELECT |
514 | # include "ev_select.c" |
563 | # include "ev_select.c" |
515 | #endif |
564 | #endif |
… | |
… | |
542 | ev_method (EV_P) |
591 | ev_method (EV_P) |
543 | { |
592 | { |
544 | return method; |
593 | return method; |
545 | } |
594 | } |
546 | |
595 | |
547 | inline int |
596 | static void |
548 | loop_init (EV_P_ int methods) |
597 | loop_init (EV_P_ int methods) |
549 | { |
598 | { |
550 | if (!method) |
599 | if (!method) |
551 | { |
600 | { |
552 | #if EV_USE_MONOTONIC |
601 | #if EV_USE_MONOTONIC |
… | |
… | |
560 | rt_now = ev_time (); |
609 | rt_now = ev_time (); |
561 | mn_now = get_clock (); |
610 | mn_now = get_clock (); |
562 | now_floor = mn_now; |
611 | now_floor = mn_now; |
563 | rtmn_diff = rt_now - mn_now; |
612 | rtmn_diff = rt_now - mn_now; |
564 | |
613 | |
565 | if (pipe (sigpipe)) |
|
|
566 | return 0; |
|
|
567 | |
|
|
568 | if (methods == EVMETHOD_AUTO) |
614 | if (methods == EVMETHOD_AUTO) |
569 | if (!enable_secure () && getenv ("LIBmethodS")) |
615 | if (!enable_secure () && getenv ("LIBEV_METHODS")) |
570 | methods = atoi (getenv ("LIBmethodS")); |
616 | methods = atoi (getenv ("LIBEV_METHODS")); |
571 | else |
617 | else |
572 | methods = EVMETHOD_ANY; |
618 | methods = EVMETHOD_ANY; |
573 | |
619 | |
574 | method = 0; |
620 | method = 0; |
|
|
621 | #if EV_USE_WIN32 |
|
|
622 | if (!method && (methods & EVMETHOD_WIN32 )) method = win32_init (EV_A_ methods); |
|
|
623 | #endif |
575 | #if EV_USE_KQUEUE |
624 | #if EV_USE_KQUEUE |
576 | if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); |
625 | if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); |
577 | #endif |
626 | #endif |
578 | #if EV_USE_EPOLL |
627 | #if EV_USE_EPOLL |
579 | if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); |
628 | if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); |
580 | #endif |
629 | #endif |
581 | #if EV_USEV_POLL |
630 | #if EV_USE_POLL |
582 | if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); |
631 | if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); |
583 | #endif |
632 | #endif |
584 | #if EV_USE_SELECT |
633 | #if EV_USE_SELECT |
585 | if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); |
634 | if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); |
586 | #endif |
635 | #endif |
|
|
636 | } |
|
|
637 | } |
587 | |
638 | |
|
|
639 | void |
|
|
640 | loop_destroy (EV_P) |
|
|
641 | { |
|
|
642 | int i; |
|
|
643 | |
|
|
644 | #if EV_USE_WIN32 |
|
|
645 | if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A); |
|
|
646 | #endif |
|
|
647 | #if EV_USE_KQUEUE |
|
|
648 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
|
|
649 | #endif |
|
|
650 | #if EV_USE_EPOLL |
|
|
651 | if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); |
|
|
652 | #endif |
|
|
653 | #if EV_USE_POLL |
|
|
654 | if (method == EVMETHOD_POLL ) poll_destroy (EV_A); |
|
|
655 | #endif |
|
|
656 | #if EV_USE_SELECT |
|
|
657 | if (method == EVMETHOD_SELECT) select_destroy (EV_A); |
|
|
658 | #endif |
|
|
659 | |
|
|
660 | for (i = NUMPRI; i--; ) |
|
|
661 | array_free (pending, [i]); |
|
|
662 | |
|
|
663 | array_free (fdchange, ); |
|
|
664 | array_free (timer, ); |
|
|
665 | array_free (periodic, ); |
|
|
666 | array_free (idle, ); |
|
|
667 | array_free (prepare, ); |
|
|
668 | array_free (check, ); |
|
|
669 | |
|
|
670 | method = 0; |
|
|
671 | /*TODO*/ |
|
|
672 | } |
|
|
673 | |
|
|
674 | void |
|
|
675 | loop_fork (EV_P) |
|
|
676 | { |
|
|
677 | /*TODO*/ |
|
|
678 | #if EV_USE_EPOLL |
|
|
679 | if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); |
|
|
680 | #endif |
|
|
681 | #if EV_USE_KQUEUE |
|
|
682 | if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); |
|
|
683 | #endif |
|
|
684 | } |
|
|
685 | |
|
|
686 | #if EV_MULTIPLICITY |
|
|
687 | struct ev_loop * |
|
|
688 | ev_loop_new (int methods) |
|
|
689 | { |
|
|
690 | struct ev_loop *loop = (struct ev_loop *)calloc (1, sizeof (struct ev_loop)); |
|
|
691 | |
|
|
692 | loop_init (EV_A_ methods); |
|
|
693 | |
|
|
694 | if (ev_method (EV_A)) |
|
|
695 | return loop; |
|
|
696 | |
|
|
697 | return 0; |
|
|
698 | } |
|
|
699 | |
|
|
700 | void |
|
|
701 | ev_loop_destroy (EV_P) |
|
|
702 | { |
|
|
703 | loop_destroy (EV_A); |
|
|
704 | free (loop); |
|
|
705 | } |
|
|
706 | |
|
|
707 | void |
|
|
708 | ev_loop_fork (EV_P) |
|
|
709 | { |
|
|
710 | loop_fork (EV_A); |
|
|
711 | } |
|
|
712 | |
|
|
713 | #endif |
|
|
714 | |
|
|
715 | #if EV_MULTIPLICITY |
|
|
716 | struct ev_loop default_loop_struct; |
|
|
717 | static struct ev_loop *default_loop; |
|
|
718 | |
|
|
719 | struct ev_loop * |
|
|
720 | #else |
|
|
721 | static int default_loop; |
|
|
722 | |
|
|
723 | int |
|
|
724 | #endif |
|
|
725 | ev_default_loop (int methods) |
|
|
726 | { |
|
|
727 | if (sigpipe [0] == sigpipe [1]) |
|
|
728 | if (pipe (sigpipe)) |
|
|
729 | return 0; |
|
|
730 | |
|
|
731 | if (!default_loop) |
|
|
732 | { |
|
|
733 | #if EV_MULTIPLICITY |
|
|
734 | struct ev_loop *loop = default_loop = &default_loop_struct; |
|
|
735 | #else |
|
|
736 | default_loop = 1; |
|
|
737 | #endif |
|
|
738 | |
|
|
739 | loop_init (EV_A_ methods); |
|
|
740 | |
588 | if (method) |
741 | if (ev_method (EV_A)) |
589 | { |
742 | { |
590 | ev_watcher_init (&sigev, sigcb); |
743 | ev_watcher_init (&sigev, sigcb); |
591 | ev_set_priority (&sigev, EV_MAXPRI); |
744 | ev_set_priority (&sigev, EV_MAXPRI); |
592 | siginit (EV_A); |
745 | siginit (EV_A); |
593 | |
746 | |
… | |
… | |
596 | ev_set_priority (&childev, EV_MAXPRI); |
749 | ev_set_priority (&childev, EV_MAXPRI); |
597 | ev_signal_start (EV_A_ &childev); |
750 | ev_signal_start (EV_A_ &childev); |
598 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
751 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
599 | #endif |
752 | #endif |
600 | } |
753 | } |
|
|
754 | else |
|
|
755 | default_loop = 0; |
601 | } |
756 | } |
602 | |
757 | |
603 | return method; |
758 | return default_loop; |
604 | } |
759 | } |
605 | |
760 | |
|
|
761 | void |
|
|
762 | ev_default_destroy (void) |
|
|
763 | { |
606 | #if EV_MULTIPLICITY |
764 | #if EV_MULTIPLICITY |
607 | |
765 | struct ev_loop *loop = default_loop; |
608 | struct ev_loop * |
|
|
609 | ev_loop_new (int methods) |
|
|
610 | { |
|
|
611 | struct ev_loop *loop = (struct ev_loop *)calloc (1, sizeof (struct ev_loop)); |
|
|
612 | |
|
|
613 | if (loop_init (EV_A_ methods)) |
|
|
614 | return loop; |
|
|
615 | |
|
|
616 | ev_loop_delete (loop); |
|
|
617 | |
|
|
618 | return 0; |
|
|
619 | } |
|
|
620 | |
|
|
621 | void |
|
|
622 | ev_loop_delete (EV_P) |
|
|
623 | { |
|
|
624 | /*TODO*/ |
|
|
625 | free (loop); |
|
|
626 | } |
|
|
627 | |
|
|
628 | #else |
|
|
629 | |
|
|
630 | int |
|
|
631 | ev_init (int methods) |
|
|
632 | { |
|
|
633 | return loop_init (methods); |
|
|
634 | } |
|
|
635 | |
|
|
636 | #endif |
766 | #endif |
637 | |
767 | |
638 | /*****************************************************************************/ |
768 | ev_ref (EV_A); /* child watcher */ |
|
|
769 | ev_signal_stop (EV_A_ &childev); |
639 | |
770 | |
640 | void |
771 | ev_ref (EV_A); /* signal watcher */ |
641 | ev_fork_prepare (void) |
772 | ev_io_stop (EV_A_ &sigev); |
642 | { |
|
|
643 | /* nop */ |
|
|
644 | } |
|
|
645 | |
773 | |
646 | void |
774 | close (sigpipe [0]); sigpipe [0] = 0; |
647 | ev_fork_parent (void) |
775 | close (sigpipe [1]); sigpipe [1] = 0; |
648 | { |
|
|
649 | /* nop */ |
|
|
650 | } |
|
|
651 | |
776 | |
|
|
777 | loop_destroy (EV_A); |
|
|
778 | } |
|
|
779 | |
652 | void |
780 | void |
653 | ev_fork_child (void) |
781 | ev_default_fork (void) |
654 | { |
782 | { |
655 | /*TODO*/ |
|
|
656 | #if !EV_MULTIPLICITY |
783 | #if EV_MULTIPLICITY |
657 | #if EV_USE_EPOLL |
784 | struct ev_loop *loop = default_loop; |
658 | if (method == EVMETHOD_EPOLL) |
|
|
659 | epoll_postfork_child (EV_A); |
|
|
660 | #endif |
785 | #endif |
|
|
786 | |
|
|
787 | loop_fork (EV_A); |
661 | |
788 | |
662 | ev_io_stop (EV_A_ &sigev); |
789 | ev_io_stop (EV_A_ &sigev); |
663 | close (sigpipe [0]); |
790 | close (sigpipe [0]); |
664 | close (sigpipe [1]); |
791 | close (sigpipe [1]); |
665 | pipe (sigpipe); |
792 | pipe (sigpipe); |
|
|
793 | |
|
|
794 | ev_ref (EV_A); /* signal watcher */ |
666 | siginit (EV_A); |
795 | siginit (EV_A); |
667 | #endif |
|
|
668 | } |
796 | } |
669 | |
797 | |
670 | /*****************************************************************************/ |
798 | /*****************************************************************************/ |
671 | |
799 | |
672 | static void |
800 | static void |
… | |
… | |
680 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
808 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
681 | |
809 | |
682 | if (p->w) |
810 | if (p->w) |
683 | { |
811 | { |
684 | p->w->pending = 0; |
812 | p->w->pending = 0; |
|
|
813 | |
685 | p->w->cb (EV_A_ p->w, p->events); |
814 | ((void (*)(EV_P_ W, int))p->w->cb) (EV_A_ p->w, p->events); |
686 | } |
815 | } |
687 | } |
816 | } |
688 | } |
817 | } |
689 | |
818 | |
690 | static void |
819 | static void |
691 | timers_reify (EV_P) |
820 | timers_reify (EV_P) |
692 | { |
821 | { |
693 | while (timercnt && timers [0]->at <= mn_now) |
822 | while (timercnt && ((WT)timers [0])->at <= mn_now) |
694 | { |
823 | { |
695 | struct ev_timer *w = timers [0]; |
824 | struct ev_timer *w = timers [0]; |
|
|
825 | |
|
|
826 | assert (("inactive timer on timer heap detected", ev_is_active (w))); |
696 | |
827 | |
697 | /* first reschedule or stop timer */ |
828 | /* first reschedule or stop timer */ |
698 | if (w->repeat) |
829 | if (w->repeat) |
699 | { |
830 | { |
700 | assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); |
831 | assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); |
701 | w->at = mn_now + w->repeat; |
832 | ((WT)w)->at = mn_now + w->repeat; |
702 | downheap ((WT *)timers, timercnt, 0); |
833 | downheap ((WT *)timers, timercnt, 0); |
703 | } |
834 | } |
704 | else |
835 | else |
705 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
836 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
706 | |
837 | |
… | |
… | |
709 | } |
840 | } |
710 | |
841 | |
711 | static void |
842 | static void |
712 | periodics_reify (EV_P) |
843 | periodics_reify (EV_P) |
713 | { |
844 | { |
714 | while (periodiccnt && periodics [0]->at <= rt_now) |
845 | while (periodiccnt && ((WT)periodics [0])->at <= rt_now) |
715 | { |
846 | { |
716 | struct ev_periodic *w = periodics [0]; |
847 | struct ev_periodic *w = periodics [0]; |
|
|
848 | |
|
|
849 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
717 | |
850 | |
718 | /* first reschedule or stop timer */ |
851 | /* first reschedule or stop timer */ |
719 | if (w->interval) |
852 | if (w->interval) |
720 | { |
853 | { |
721 | w->at += floor ((rt_now - w->at) / w->interval + 1.) * w->interval; |
854 | ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; |
722 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", w->at > rt_now)); |
855 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now)); |
723 | downheap ((WT *)periodics, periodiccnt, 0); |
856 | downheap ((WT *)periodics, periodiccnt, 0); |
724 | } |
857 | } |
725 | else |
858 | else |
726 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
859 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
727 | |
860 | |
… | |
… | |
739 | { |
872 | { |
740 | struct ev_periodic *w = periodics [i]; |
873 | struct ev_periodic *w = periodics [i]; |
741 | |
874 | |
742 | if (w->interval) |
875 | if (w->interval) |
743 | { |
876 | { |
744 | ev_tstamp diff = ceil ((rt_now - w->at) / w->interval) * w->interval; |
877 | ev_tstamp diff = ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
745 | |
878 | |
746 | if (fabs (diff) >= 1e-4) |
879 | if (fabs (diff) >= 1e-4) |
747 | { |
880 | { |
748 | ev_periodic_stop (EV_A_ w); |
881 | ev_periodic_stop (EV_A_ w); |
749 | ev_periodic_start (EV_A_ w); |
882 | ev_periodic_start (EV_A_ w); |
… | |
… | |
810 | { |
943 | { |
811 | periodics_reschedule (EV_A); |
944 | periodics_reschedule (EV_A); |
812 | |
945 | |
813 | /* adjust timers. this is easy, as the offset is the same for all */ |
946 | /* adjust timers. this is easy, as the offset is the same for all */ |
814 | for (i = 0; i < timercnt; ++i) |
947 | for (i = 0; i < timercnt; ++i) |
815 | timers [i]->at += rt_now - mn_now; |
948 | ((WT)timers [i])->at += rt_now - mn_now; |
816 | } |
949 | } |
817 | |
950 | |
818 | mn_now = rt_now; |
951 | mn_now = rt_now; |
819 | } |
952 | } |
820 | } |
953 | } |
… | |
… | |
871 | { |
1004 | { |
872 | block = MAX_BLOCKTIME; |
1005 | block = MAX_BLOCKTIME; |
873 | |
1006 | |
874 | if (timercnt) |
1007 | if (timercnt) |
875 | { |
1008 | { |
876 | ev_tstamp to = timers [0]->at - mn_now + method_fudge; |
1009 | ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge; |
877 | if (block > to) block = to; |
1010 | if (block > to) block = to; |
878 | } |
1011 | } |
879 | |
1012 | |
880 | if (periodiccnt) |
1013 | if (periodiccnt) |
881 | { |
1014 | { |
882 | ev_tstamp to = periodics [0]->at - rt_now + method_fudge; |
1015 | ev_tstamp to = ((WT)periodics [0])->at - rt_now + method_fudge; |
883 | if (block > to) block = to; |
1016 | if (block > to) block = to; |
884 | } |
1017 | } |
885 | |
1018 | |
886 | if (block < 0.) block = 0.; |
1019 | if (block < 0.) block = 0.; |
887 | } |
1020 | } |
… | |
… | |
1004 | ev_timer_start (EV_P_ struct ev_timer *w) |
1137 | ev_timer_start (EV_P_ struct ev_timer *w) |
1005 | { |
1138 | { |
1006 | if (ev_is_active (w)) |
1139 | if (ev_is_active (w)) |
1007 | return; |
1140 | return; |
1008 | |
1141 | |
1009 | w->at += mn_now; |
1142 | ((WT)w)->at += mn_now; |
1010 | |
1143 | |
1011 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1144 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1012 | |
1145 | |
1013 | ev_start (EV_A_ (W)w, ++timercnt); |
1146 | ev_start (EV_A_ (W)w, ++timercnt); |
1014 | array_needsize (timers, timermax, timercnt, ); |
1147 | array_needsize (timers, timermax, timercnt, ); |
1015 | timers [timercnt - 1] = w; |
1148 | timers [timercnt - 1] = w; |
1016 | upheap ((WT *)timers, timercnt - 1); |
1149 | upheap ((WT *)timers, timercnt - 1); |
|
|
1150 | |
|
|
1151 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1017 | } |
1152 | } |
1018 | |
1153 | |
1019 | void |
1154 | void |
1020 | ev_timer_stop (EV_P_ struct ev_timer *w) |
1155 | ev_timer_stop (EV_P_ struct ev_timer *w) |
1021 | { |
1156 | { |
1022 | ev_clear_pending (EV_A_ (W)w); |
1157 | ev_clear_pending (EV_A_ (W)w); |
1023 | if (!ev_is_active (w)) |
1158 | if (!ev_is_active (w)) |
1024 | return; |
1159 | return; |
1025 | |
1160 | |
|
|
1161 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
|
|
1162 | |
1026 | if (w->active < timercnt--) |
1163 | if (((W)w)->active < timercnt--) |
1027 | { |
1164 | { |
1028 | timers [w->active - 1] = timers [timercnt]; |
1165 | timers [((W)w)->active - 1] = timers [timercnt]; |
1029 | downheap ((WT *)timers, timercnt, w->active - 1); |
1166 | downheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1030 | } |
1167 | } |
1031 | |
1168 | |
1032 | w->at = w->repeat; |
1169 | ((WT)w)->at = w->repeat; |
1033 | |
1170 | |
1034 | ev_stop (EV_A_ (W)w); |
1171 | ev_stop (EV_A_ (W)w); |
1035 | } |
1172 | } |
1036 | |
1173 | |
1037 | void |
1174 | void |
… | |
… | |
1039 | { |
1176 | { |
1040 | if (ev_is_active (w)) |
1177 | if (ev_is_active (w)) |
1041 | { |
1178 | { |
1042 | if (w->repeat) |
1179 | if (w->repeat) |
1043 | { |
1180 | { |
1044 | w->at = mn_now + w->repeat; |
1181 | ((WT)w)->at = mn_now + w->repeat; |
1045 | downheap ((WT *)timers, timercnt, w->active - 1); |
1182 | downheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1046 | } |
1183 | } |
1047 | else |
1184 | else |
1048 | ev_timer_stop (EV_A_ w); |
1185 | ev_timer_stop (EV_A_ w); |
1049 | } |
1186 | } |
1050 | else if (w->repeat) |
1187 | else if (w->repeat) |
… | |
… | |
1059 | |
1196 | |
1060 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1197 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1061 | |
1198 | |
1062 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1199 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1063 | if (w->interval) |
1200 | if (w->interval) |
1064 | w->at += ceil ((rt_now - w->at) / w->interval) * w->interval; |
1201 | ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1065 | |
1202 | |
1066 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1203 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1067 | array_needsize (periodics, periodicmax, periodiccnt, ); |
1204 | array_needsize (periodics, periodicmax, periodiccnt, ); |
1068 | periodics [periodiccnt - 1] = w; |
1205 | periodics [periodiccnt - 1] = w; |
1069 | upheap ((WT *)periodics, periodiccnt - 1); |
1206 | upheap ((WT *)periodics, periodiccnt - 1); |
|
|
1207 | |
|
|
1208 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1070 | } |
1209 | } |
1071 | |
1210 | |
1072 | void |
1211 | void |
1073 | ev_periodic_stop (EV_P_ struct ev_periodic *w) |
1212 | ev_periodic_stop (EV_P_ struct ev_periodic *w) |
1074 | { |
1213 | { |
1075 | ev_clear_pending (EV_A_ (W)w); |
1214 | ev_clear_pending (EV_A_ (W)w); |
1076 | if (!ev_is_active (w)) |
1215 | if (!ev_is_active (w)) |
1077 | return; |
1216 | return; |
1078 | |
1217 | |
|
|
1218 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
|
|
1219 | |
1079 | if (w->active < periodiccnt--) |
1220 | if (((W)w)->active < periodiccnt--) |
1080 | { |
1221 | { |
1081 | periodics [w->active - 1] = periodics [periodiccnt]; |
1222 | periodics [((W)w)->active - 1] = periodics [periodiccnt]; |
1082 | downheap ((WT *)periodics, periodiccnt, w->active - 1); |
1223 | downheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); |
1083 | } |
1224 | } |
1084 | |
1225 | |
|
|
1226 | ev_stop (EV_A_ (W)w); |
|
|
1227 | } |
|
|
1228 | |
|
|
1229 | void |
|
|
1230 | ev_idle_start (EV_P_ struct ev_idle *w) |
|
|
1231 | { |
|
|
1232 | if (ev_is_active (w)) |
|
|
1233 | return; |
|
|
1234 | |
|
|
1235 | ev_start (EV_A_ (W)w, ++idlecnt); |
|
|
1236 | array_needsize (idles, idlemax, idlecnt, ); |
|
|
1237 | idles [idlecnt - 1] = w; |
|
|
1238 | } |
|
|
1239 | |
|
|
1240 | void |
|
|
1241 | ev_idle_stop (EV_P_ struct ev_idle *w) |
|
|
1242 | { |
|
|
1243 | ev_clear_pending (EV_A_ (W)w); |
|
|
1244 | if (ev_is_active (w)) |
|
|
1245 | return; |
|
|
1246 | |
|
|
1247 | idles [((W)w)->active - 1] = idles [--idlecnt]; |
|
|
1248 | ev_stop (EV_A_ (W)w); |
|
|
1249 | } |
|
|
1250 | |
|
|
1251 | void |
|
|
1252 | ev_prepare_start (EV_P_ struct ev_prepare *w) |
|
|
1253 | { |
|
|
1254 | if (ev_is_active (w)) |
|
|
1255 | return; |
|
|
1256 | |
|
|
1257 | ev_start (EV_A_ (W)w, ++preparecnt); |
|
|
1258 | array_needsize (prepares, preparemax, preparecnt, ); |
|
|
1259 | prepares [preparecnt - 1] = w; |
|
|
1260 | } |
|
|
1261 | |
|
|
1262 | void |
|
|
1263 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
|
|
1264 | { |
|
|
1265 | ev_clear_pending (EV_A_ (W)w); |
|
|
1266 | if (ev_is_active (w)) |
|
|
1267 | return; |
|
|
1268 | |
|
|
1269 | prepares [((W)w)->active - 1] = prepares [--preparecnt]; |
|
|
1270 | ev_stop (EV_A_ (W)w); |
|
|
1271 | } |
|
|
1272 | |
|
|
1273 | void |
|
|
1274 | ev_check_start (EV_P_ struct ev_check *w) |
|
|
1275 | { |
|
|
1276 | if (ev_is_active (w)) |
|
|
1277 | return; |
|
|
1278 | |
|
|
1279 | ev_start (EV_A_ (W)w, ++checkcnt); |
|
|
1280 | array_needsize (checks, checkmax, checkcnt, ); |
|
|
1281 | checks [checkcnt - 1] = w; |
|
|
1282 | } |
|
|
1283 | |
|
|
1284 | void |
|
|
1285 | ev_check_stop (EV_P_ struct ev_check *w) |
|
|
1286 | { |
|
|
1287 | ev_clear_pending (EV_A_ (W)w); |
|
|
1288 | if (ev_is_active (w)) |
|
|
1289 | return; |
|
|
1290 | |
|
|
1291 | checks [((W)w)->active - 1] = checks [--checkcnt]; |
1085 | ev_stop (EV_A_ (W)w); |
1292 | ev_stop (EV_A_ (W)w); |
1086 | } |
1293 | } |
1087 | |
1294 | |
1088 | #ifndef SA_RESTART |
1295 | #ifndef SA_RESTART |
1089 | # define SA_RESTART 0 |
1296 | # define SA_RESTART 0 |
1090 | #endif |
1297 | #endif |
1091 | |
1298 | |
1092 | void |
1299 | void |
1093 | ev_signal_start (EV_P_ struct ev_signal *w) |
1300 | ev_signal_start (EV_P_ struct ev_signal *w) |
1094 | { |
1301 | { |
|
|
1302 | #if EV_MULTIPLICITY |
|
|
1303 | assert (("signal watchers are only supported in the default loop", loop == default_loop)); |
|
|
1304 | #endif |
1095 | if (ev_is_active (w)) |
1305 | if (ev_is_active (w)) |
1096 | return; |
1306 | return; |
1097 | |
1307 | |
1098 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
1308 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
1099 | |
1309 | |
1100 | ev_start (EV_A_ (W)w, 1); |
1310 | ev_start (EV_A_ (W)w, 1); |
1101 | array_needsize (signals, signalmax, w->signum, signals_init); |
1311 | array_needsize (signals, signalmax, w->signum, signals_init); |
1102 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1312 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1103 | |
1313 | |
1104 | if (!w->next) |
1314 | if (!((WL)w)->next) |
1105 | { |
1315 | { |
1106 | struct sigaction sa; |
1316 | struct sigaction sa; |
1107 | sa.sa_handler = sighandler; |
1317 | sa.sa_handler = sighandler; |
1108 | sigfillset (&sa.sa_mask); |
1318 | sigfillset (&sa.sa_mask); |
1109 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
1319 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
… | |
… | |
1124 | if (!signals [w->signum - 1].head) |
1334 | if (!signals [w->signum - 1].head) |
1125 | signal (w->signum, SIG_DFL); |
1335 | signal (w->signum, SIG_DFL); |
1126 | } |
1336 | } |
1127 | |
1337 | |
1128 | void |
1338 | void |
1129 | ev_idle_start (EV_P_ struct ev_idle *w) |
|
|
1130 | { |
|
|
1131 | if (ev_is_active (w)) |
|
|
1132 | return; |
|
|
1133 | |
|
|
1134 | ev_start (EV_A_ (W)w, ++idlecnt); |
|
|
1135 | array_needsize (idles, idlemax, idlecnt, ); |
|
|
1136 | idles [idlecnt - 1] = w; |
|
|
1137 | } |
|
|
1138 | |
|
|
1139 | void |
|
|
1140 | ev_idle_stop (EV_P_ struct ev_idle *w) |
|
|
1141 | { |
|
|
1142 | ev_clear_pending (EV_A_ (W)w); |
|
|
1143 | if (ev_is_active (w)) |
|
|
1144 | return; |
|
|
1145 | |
|
|
1146 | idles [w->active - 1] = idles [--idlecnt]; |
|
|
1147 | ev_stop (EV_A_ (W)w); |
|
|
1148 | } |
|
|
1149 | |
|
|
1150 | void |
|
|
1151 | ev_prepare_start (EV_P_ struct ev_prepare *w) |
|
|
1152 | { |
|
|
1153 | if (ev_is_active (w)) |
|
|
1154 | return; |
|
|
1155 | |
|
|
1156 | ev_start (EV_A_ (W)w, ++preparecnt); |
|
|
1157 | array_needsize (prepares, preparemax, preparecnt, ); |
|
|
1158 | prepares [preparecnt - 1] = w; |
|
|
1159 | } |
|
|
1160 | |
|
|
1161 | void |
|
|
1162 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
|
|
1163 | { |
|
|
1164 | ev_clear_pending (EV_A_ (W)w); |
|
|
1165 | if (ev_is_active (w)) |
|
|
1166 | return; |
|
|
1167 | |
|
|
1168 | prepares [w->active - 1] = prepares [--preparecnt]; |
|
|
1169 | ev_stop (EV_A_ (W)w); |
|
|
1170 | } |
|
|
1171 | |
|
|
1172 | void |
|
|
1173 | ev_check_start (EV_P_ struct ev_check *w) |
|
|
1174 | { |
|
|
1175 | if (ev_is_active (w)) |
|
|
1176 | return; |
|
|
1177 | |
|
|
1178 | ev_start (EV_A_ (W)w, ++checkcnt); |
|
|
1179 | array_needsize (checks, checkmax, checkcnt, ); |
|
|
1180 | checks [checkcnt - 1] = w; |
|
|
1181 | } |
|
|
1182 | |
|
|
1183 | void |
|
|
1184 | ev_check_stop (EV_P_ struct ev_check *w) |
|
|
1185 | { |
|
|
1186 | ev_clear_pending (EV_A_ (W)w); |
|
|
1187 | if (ev_is_active (w)) |
|
|
1188 | return; |
|
|
1189 | |
|
|
1190 | checks [w->active - 1] = checks [--checkcnt]; |
|
|
1191 | ev_stop (EV_A_ (W)w); |
|
|
1192 | } |
|
|
1193 | |
|
|
1194 | void |
|
|
1195 | ev_child_start (EV_P_ struct ev_child *w) |
1339 | ev_child_start (EV_P_ struct ev_child *w) |
1196 | { |
1340 | { |
|
|
1341 | #if EV_MULTIPLICITY |
|
|
1342 | assert (("child watchers are only supported in the default loop", loop == default_loop)); |
|
|
1343 | #endif |
1197 | if (ev_is_active (w)) |
1344 | if (ev_is_active (w)) |
1198 | return; |
1345 | return; |
1199 | |
1346 | |
1200 | ev_start (EV_A_ (W)w, 1); |
1347 | ev_start (EV_A_ (W)w, 1); |
1201 | wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1348 | wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
… | |
… | |
1273 | ev_timer_start (EV_A_ &once->to); |
1420 | ev_timer_start (EV_A_ &once->to); |
1274 | } |
1421 | } |
1275 | } |
1422 | } |
1276 | } |
1423 | } |
1277 | |
1424 | |
1278 | /*****************************************************************************/ |
|
|
1279 | |
|
|
1280 | #if 0 |
|
|
1281 | |
|
|
1282 | struct ev_io wio; |
|
|
1283 | |
|
|
1284 | static void |
|
|
1285 | sin_cb (struct ev_io *w, int revents) |
|
|
1286 | { |
|
|
1287 | fprintf (stderr, "sin %d, revents %d\n", w->fd, revents); |
|
|
1288 | } |
|
|
1289 | |
|
|
1290 | static void |
|
|
1291 | ocb (struct ev_timer *w, int revents) |
|
|
1292 | { |
|
|
1293 | //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data); |
|
|
1294 | ev_timer_stop (w); |
|
|
1295 | ev_timer_start (w); |
|
|
1296 | } |
|
|
1297 | |
|
|
1298 | static void |
|
|
1299 | scb (struct ev_signal *w, int revents) |
|
|
1300 | { |
|
|
1301 | fprintf (stderr, "signal %x,%d\n", revents, w->signum); |
|
|
1302 | ev_io_stop (&wio); |
|
|
1303 | ev_io_start (&wio); |
|
|
1304 | } |
|
|
1305 | |
|
|
1306 | static void |
|
|
1307 | gcb (struct ev_signal *w, int revents) |
|
|
1308 | { |
|
|
1309 | fprintf (stderr, "generic %x\n", revents); |
|
|
1310 | |
|
|
1311 | } |
|
|
1312 | |
|
|
1313 | int main (void) |
|
|
1314 | { |
|
|
1315 | ev_init (0); |
|
|
1316 | |
|
|
1317 | ev_io_init (&wio, sin_cb, 0, EV_READ); |
|
|
1318 | ev_io_start (&wio); |
|
|
1319 | |
|
|
1320 | struct ev_timer t[10000]; |
|
|
1321 | |
|
|
1322 | #if 0 |
|
|
1323 | int i; |
|
|
1324 | for (i = 0; i < 10000; ++i) |
|
|
1325 | { |
|
|
1326 | struct ev_timer *w = t + i; |
|
|
1327 | ev_watcher_init (w, ocb, i); |
|
|
1328 | ev_timer_init_abs (w, ocb, drand48 (), 0.99775533); |
|
|
1329 | ev_timer_start (w); |
|
|
1330 | if (drand48 () < 0.5) |
|
|
1331 | ev_timer_stop (w); |
|
|
1332 | } |
|
|
1333 | #endif |
|
|
1334 | |
|
|
1335 | struct ev_timer t1; |
|
|
1336 | ev_timer_init (&t1, ocb, 5, 10); |
|
|
1337 | ev_timer_start (&t1); |
|
|
1338 | |
|
|
1339 | struct ev_signal sig; |
|
|
1340 | ev_signal_init (&sig, scb, SIGQUIT); |
|
|
1341 | ev_signal_start (&sig); |
|
|
1342 | |
|
|
1343 | struct ev_check cw; |
|
|
1344 | ev_check_init (&cw, gcb); |
|
|
1345 | ev_check_start (&cw); |
|
|
1346 | |
|
|
1347 | struct ev_idle iw; |
|
|
1348 | ev_idle_init (&iw, gcb); |
|
|
1349 | ev_idle_start (&iw); |
|
|
1350 | |
|
|
1351 | ev_loop (0); |
|
|
1352 | |
|
|
1353 | return 0; |
|
|
1354 | } |
|
|
1355 | |
|
|
1356 | #endif |
|
|
1357 | |
|
|
1358 | |
|
|
1359 | |
|
|
1360 | |
|
|