… | |
… | |
126 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
126 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
127 | #define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */ |
127 | #define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */ |
128 | #define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ |
128 | #define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ |
129 | /*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */ |
129 | /*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */ |
130 | |
130 | |
|
|
131 | #ifdef EV_H |
|
|
132 | # include EV_H |
|
|
133 | #else |
131 | #include "ev.h" |
134 | # include "ev.h" |
|
|
135 | #endif |
132 | |
136 | |
133 | #if __GNUC__ >= 3 |
137 | #if __GNUC__ >= 3 |
134 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
138 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
135 | # define inline inline |
139 | # define inline inline |
136 | #else |
140 | #else |
… | |
… | |
215 | int events; |
219 | int events; |
216 | } ANPENDING; |
220 | } ANPENDING; |
217 | |
221 | |
218 | #if EV_MULTIPLICITY |
222 | #if EV_MULTIPLICITY |
219 | |
223 | |
220 | struct ev_loop |
224 | struct ev_loop |
221 | { |
225 | { |
222 | # define VAR(name,decl) decl; |
226 | #define VAR(name,decl) decl; |
223 | # include "ev_vars.h" |
227 | #include "ev_vars.h" |
224 | }; |
|
|
225 | # undef VAR |
228 | #undef VAR |
|
|
229 | }; |
226 | # include "ev_wrap.h" |
230 | #include "ev_wrap.h" |
|
|
231 | |
|
|
232 | struct ev_loop default_loop_struct; |
|
|
233 | static struct ev_loop *default_loop; |
227 | |
234 | |
228 | #else |
235 | #else |
229 | |
236 | |
230 | # define VAR(name,decl) static decl; |
237 | #define VAR(name,decl) static decl; |
231 | # include "ev_vars.h" |
238 | #include "ev_vars.h" |
232 | # undef VAR |
239 | #undef VAR |
|
|
240 | |
|
|
241 | static int default_loop; |
233 | |
242 | |
234 | #endif |
243 | #endif |
235 | |
244 | |
236 | /*****************************************************************************/ |
245 | /*****************************************************************************/ |
237 | |
246 | |
… | |
… | |
316 | |
325 | |
317 | ++base; |
326 | ++base; |
318 | } |
327 | } |
319 | } |
328 | } |
320 | |
329 | |
321 | static void |
330 | void |
322 | event (EV_P_ W w, int events) |
331 | ev_feed_event (EV_P_ void *w, int revents) |
323 | { |
332 | { |
|
|
333 | W w_ = (W)w; |
|
|
334 | |
324 | if (w->pending) |
335 | if (w_->pending) |
325 | { |
336 | { |
326 | pendings [ABSPRI (w)][w->pending - 1].events |= events; |
337 | pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; |
327 | return; |
338 | return; |
328 | } |
339 | } |
329 | |
340 | |
330 | w->pending = ++pendingcnt [ABSPRI (w)]; |
341 | w_->pending = ++pendingcnt [ABSPRI (w_)]; |
331 | array_needsize (ANPENDING, pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], (void)); |
342 | array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], (void)); |
332 | pendings [ABSPRI (w)][w->pending - 1].w = w; |
343 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
333 | pendings [ABSPRI (w)][w->pending - 1].events = events; |
344 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
334 | } |
345 | } |
335 | |
346 | |
336 | static void |
347 | static void |
337 | queue_events (EV_P_ W *events, int eventcnt, int type) |
348 | queue_events (EV_P_ W *events, int eventcnt, int type) |
338 | { |
349 | { |
339 | int i; |
350 | int i; |
340 | |
351 | |
341 | for (i = 0; i < eventcnt; ++i) |
352 | for (i = 0; i < eventcnt; ++i) |
342 | event (EV_A_ events [i], type); |
353 | ev_feed_event (EV_A_ events [i], type); |
343 | } |
354 | } |
344 | |
355 | |
345 | static void |
356 | inline void |
346 | fd_event (EV_P_ int fd, int events) |
357 | fd_event (EV_P_ int fd, int revents) |
347 | { |
358 | { |
348 | ANFD *anfd = anfds + fd; |
359 | ANFD *anfd = anfds + fd; |
349 | struct ev_io *w; |
360 | struct ev_io *w; |
350 | |
361 | |
351 | for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) |
362 | for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) |
352 | { |
363 | { |
353 | int ev = w->events & events; |
364 | int ev = w->events & revents; |
354 | |
365 | |
355 | if (ev) |
366 | if (ev) |
356 | event (EV_A_ (W)w, ev); |
367 | ev_feed_event (EV_A_ (W)w, ev); |
357 | } |
368 | } |
|
|
369 | } |
|
|
370 | |
|
|
371 | void |
|
|
372 | ev_feed_fd_event (EV_P_ int fd, int revents) |
|
|
373 | { |
|
|
374 | fd_event (EV_A_ fd, revents); |
358 | } |
375 | } |
359 | |
376 | |
360 | /*****************************************************************************/ |
377 | /*****************************************************************************/ |
361 | |
378 | |
362 | static void |
379 | static void |
… | |
… | |
403 | struct ev_io *w; |
420 | struct ev_io *w; |
404 | |
421 | |
405 | while ((w = (struct ev_io *)anfds [fd].head)) |
422 | while ((w = (struct ev_io *)anfds [fd].head)) |
406 | { |
423 | { |
407 | ev_io_stop (EV_A_ w); |
424 | ev_io_stop (EV_A_ w); |
408 | event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
425 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
409 | } |
426 | } |
410 | } |
427 | } |
411 | |
428 | |
412 | static int |
429 | static int |
413 | fd_valid (int fd) |
430 | fd_valid (int fd) |
… | |
… | |
501 | |
518 | |
502 | heap [k] = w; |
519 | heap [k] = w; |
503 | ((W)heap [k])->active = k + 1; |
520 | ((W)heap [k])->active = k + 1; |
504 | } |
521 | } |
505 | |
522 | |
|
|
523 | inline void |
|
|
524 | adjustheap (WT *heap, int N, int k, ev_tstamp at) |
|
|
525 | { |
|
|
526 | ev_tstamp old_at = heap [k]->at; |
|
|
527 | heap [k]->at = at; |
|
|
528 | |
|
|
529 | if (old_at < at) |
|
|
530 | downheap (heap, N, k); |
|
|
531 | else |
|
|
532 | upheap (heap, k); |
|
|
533 | } |
|
|
534 | |
506 | /*****************************************************************************/ |
535 | /*****************************************************************************/ |
507 | |
536 | |
508 | typedef struct |
537 | typedef struct |
509 | { |
538 | { |
510 | WL head; |
539 | WL head; |
… | |
… | |
541 | |
570 | |
542 | if (!gotsig) |
571 | if (!gotsig) |
543 | { |
572 | { |
544 | int old_errno = errno; |
573 | int old_errno = errno; |
545 | gotsig = 1; |
574 | gotsig = 1; |
|
|
575 | #ifdef WIN32 |
|
|
576 | send (sigpipe [1], &signum, 1, MSG_DONTWAIT); |
|
|
577 | #else |
546 | write (sigpipe [1], &signum, 1); |
578 | write (sigpipe [1], &signum, 1); |
|
|
579 | #endif |
547 | errno = old_errno; |
580 | errno = old_errno; |
548 | } |
581 | } |
549 | } |
582 | } |
550 | |
583 | |
|
|
584 | void |
|
|
585 | ev_feed_signal_event (EV_P_ int signum) |
|
|
586 | { |
|
|
587 | WL w; |
|
|
588 | |
|
|
589 | #if EV_MULTIPLICITY |
|
|
590 | assert (("feeding signal events is only supported in the default loop", loop == default_loop)); |
|
|
591 | #endif |
|
|
592 | |
|
|
593 | --signum; |
|
|
594 | |
|
|
595 | if (signum < 0 || signum >= signalmax) |
|
|
596 | return; |
|
|
597 | |
|
|
598 | signals [signum].gotsig = 0; |
|
|
599 | |
|
|
600 | for (w = signals [signum].head; w; w = w->next) |
|
|
601 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
|
|
602 | } |
|
|
603 | |
551 | static void |
604 | static void |
552 | sigcb (EV_P_ struct ev_io *iow, int revents) |
605 | sigcb (EV_P_ struct ev_io *iow, int revents) |
553 | { |
606 | { |
554 | WL w; |
|
|
555 | int signum; |
607 | int signum; |
556 | |
608 | |
|
|
609 | #ifdef WIN32 |
|
|
610 | recv (sigpipe [0], &revents, 1, MSG_DONTWAIT); |
|
|
611 | #else |
557 | read (sigpipe [0], &revents, 1); |
612 | read (sigpipe [0], &revents, 1); |
|
|
613 | #endif |
558 | gotsig = 0; |
614 | gotsig = 0; |
559 | |
615 | |
560 | for (signum = signalmax; signum--; ) |
616 | for (signum = signalmax; signum--; ) |
561 | if (signals [signum].gotsig) |
617 | if (signals [signum].gotsig) |
562 | { |
618 | ev_feed_signal_event (EV_A_ signum + 1); |
563 | signals [signum].gotsig = 0; |
|
|
564 | |
|
|
565 | for (w = signals [signum].head; w; w = w->next) |
|
|
566 | event (EV_A_ (W)w, EV_SIGNAL); |
|
|
567 | } |
|
|
568 | } |
619 | } |
569 | |
620 | |
570 | static void |
621 | static void |
571 | siginit (EV_P) |
622 | siginit (EV_P) |
572 | { |
623 | { |
… | |
… | |
605 | if (w->pid == pid || !w->pid) |
656 | if (w->pid == pid || !w->pid) |
606 | { |
657 | { |
607 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
658 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
608 | w->rpid = pid; |
659 | w->rpid = pid; |
609 | w->rstatus = status; |
660 | w->rstatus = status; |
610 | event (EV_A_ (W)w, EV_CHILD); |
661 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
611 | } |
662 | } |
612 | } |
663 | } |
613 | |
664 | |
614 | static void |
665 | static void |
615 | childcb (EV_P_ struct ev_signal *sw, int revents) |
666 | childcb (EV_P_ struct ev_signal *sw, int revents) |
… | |
… | |
617 | int pid, status; |
668 | int pid, status; |
618 | |
669 | |
619 | if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
670 | if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
620 | { |
671 | { |
621 | /* make sure we are called again until all childs have been reaped */ |
672 | /* make sure we are called again until all childs have been reaped */ |
622 | event (EV_A_ (W)sw, EV_SIGNAL); |
673 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
623 | |
674 | |
624 | child_reap (EV_A_ sw, pid, pid, status); |
675 | child_reap (EV_A_ sw, pid, pid, status); |
625 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */ |
676 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */ |
626 | } |
677 | } |
627 | } |
678 | } |
… | |
… | |
712 | #endif |
763 | #endif |
713 | #if EV_USE_SELECT |
764 | #if EV_USE_SELECT |
714 | if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); |
765 | if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); |
715 | #endif |
766 | #endif |
716 | |
767 | |
717 | ev_watcher_init (&sigev, sigcb); |
768 | ev_init (&sigev, sigcb); |
718 | ev_set_priority (&sigev, EV_MAXPRI); |
769 | ev_set_priority (&sigev, EV_MAXPRI); |
719 | } |
770 | } |
720 | } |
771 | } |
721 | |
772 | |
722 | void |
773 | void |
… | |
… | |
812 | } |
863 | } |
813 | |
864 | |
814 | #endif |
865 | #endif |
815 | |
866 | |
816 | #if EV_MULTIPLICITY |
867 | #if EV_MULTIPLICITY |
817 | struct ev_loop default_loop_struct; |
|
|
818 | static struct ev_loop *default_loop; |
|
|
819 | |
|
|
820 | struct ev_loop * |
868 | struct ev_loop * |
821 | #else |
869 | #else |
822 | static int default_loop; |
|
|
823 | |
|
|
824 | int |
870 | int |
825 | #endif |
871 | #endif |
826 | ev_default_loop (int methods) |
872 | ev_default_loop (int methods) |
827 | { |
873 | { |
828 | if (sigpipe [0] == sigpipe [1]) |
874 | if (sigpipe [0] == sigpipe [1]) |
… | |
… | |
889 | postfork = 1; |
935 | postfork = 1; |
890 | } |
936 | } |
891 | |
937 | |
892 | /*****************************************************************************/ |
938 | /*****************************************************************************/ |
893 | |
939 | |
|
|
940 | static int |
|
|
941 | any_pending (EV_P) |
|
|
942 | { |
|
|
943 | int pri; |
|
|
944 | |
|
|
945 | for (pri = NUMPRI; pri--; ) |
|
|
946 | if (pendingcnt [pri]) |
|
|
947 | return 1; |
|
|
948 | |
|
|
949 | return 0; |
|
|
950 | } |
|
|
951 | |
894 | static void |
952 | static void |
895 | call_pending (EV_P) |
953 | call_pending (EV_P) |
896 | { |
954 | { |
897 | int pri; |
955 | int pri; |
898 | |
956 | |
… | |
… | |
902 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
960 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
903 | |
961 | |
904 | if (p->w) |
962 | if (p->w) |
905 | { |
963 | { |
906 | p->w->pending = 0; |
964 | p->w->pending = 0; |
907 | p->w->cb (EV_A_ p->w, p->events); |
965 | EV_CB_INVOKE (p->w, p->events); |
908 | } |
966 | } |
909 | } |
967 | } |
910 | } |
968 | } |
911 | |
969 | |
912 | static void |
970 | static void |
… | |
… | |
926 | downheap ((WT *)timers, timercnt, 0); |
984 | downheap ((WT *)timers, timercnt, 0); |
927 | } |
985 | } |
928 | else |
986 | else |
929 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
987 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
930 | |
988 | |
931 | event (EV_A_ (W)w, EV_TIMEOUT); |
989 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
932 | } |
990 | } |
933 | } |
991 | } |
934 | |
992 | |
935 | static void |
993 | static void |
936 | periodics_reify (EV_P) |
994 | periodics_reify (EV_P) |
… | |
… | |
940 | struct ev_periodic *w = periodics [0]; |
998 | struct ev_periodic *w = periodics [0]; |
941 | |
999 | |
942 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
1000 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
943 | |
1001 | |
944 | /* first reschedule or stop timer */ |
1002 | /* first reschedule or stop timer */ |
|
|
1003 | if (w->reschedule_cb) |
|
|
1004 | { |
|
|
1005 | ev_tstamp at = ((WT)w)->at = w->reschedule_cb (w, rt_now + 0.0001); |
|
|
1006 | |
|
|
1007 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > rt_now)); |
|
|
1008 | downheap ((WT *)periodics, periodiccnt, 0); |
|
|
1009 | } |
945 | if (w->interval) |
1010 | else if (w->interval) |
946 | { |
1011 | { |
947 | ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; |
1012 | ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; |
948 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now)); |
1013 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now)); |
949 | downheap ((WT *)periodics, periodiccnt, 0); |
1014 | downheap ((WT *)periodics, periodiccnt, 0); |
950 | } |
1015 | } |
951 | else |
1016 | else |
952 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1017 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
953 | |
1018 | |
954 | event (EV_A_ (W)w, EV_PERIODIC); |
1019 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
955 | } |
1020 | } |
956 | } |
1021 | } |
957 | |
1022 | |
958 | static void |
1023 | static void |
959 | periodics_reschedule (EV_P) |
1024 | periodics_reschedule (EV_P) |
… | |
… | |
963 | /* adjust periodics after time jump */ |
1028 | /* adjust periodics after time jump */ |
964 | for (i = 0; i < periodiccnt; ++i) |
1029 | for (i = 0; i < periodiccnt; ++i) |
965 | { |
1030 | { |
966 | struct ev_periodic *w = periodics [i]; |
1031 | struct ev_periodic *w = periodics [i]; |
967 | |
1032 | |
|
|
1033 | if (w->reschedule_cb) |
|
|
1034 | ((WT)w)->at = w->reschedule_cb (w, rt_now); |
968 | if (w->interval) |
1035 | else if (w->interval) |
969 | { |
|
|
970 | ev_tstamp diff = ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1036 | ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
971 | |
|
|
972 | if (fabs (diff) >= 1e-4) |
|
|
973 | { |
|
|
974 | ev_periodic_stop (EV_A_ w); |
|
|
975 | ev_periodic_start (EV_A_ w); |
|
|
976 | |
|
|
977 | i = 0; /* restart loop, inefficient, but time jumps should be rare */ |
|
|
978 | } |
|
|
979 | } |
|
|
980 | } |
1037 | } |
|
|
1038 | |
|
|
1039 | /* now rebuild the heap */ |
|
|
1040 | for (i = periodiccnt >> 1; i--; ) |
|
|
1041 | downheap ((WT *)periodics, periodiccnt, i); |
981 | } |
1042 | } |
982 | |
1043 | |
983 | inline int |
1044 | inline int |
984 | time_update_monotonic (EV_P) |
1045 | time_update_monotonic (EV_P) |
985 | { |
1046 | { |
… | |
… | |
1081 | /* update fd-related kernel structures */ |
1142 | /* update fd-related kernel structures */ |
1082 | fd_reify (EV_A); |
1143 | fd_reify (EV_A); |
1083 | |
1144 | |
1084 | /* calculate blocking time */ |
1145 | /* calculate blocking time */ |
1085 | |
1146 | |
1086 | /* we only need this for !monotonic clockor timers, but as we basically |
1147 | /* we only need this for !monotonic clock or timers, but as we basically |
1087 | always have timers, we just calculate it always */ |
1148 | always have timers, we just calculate it always */ |
1088 | #if EV_USE_MONOTONIC |
1149 | #if EV_USE_MONOTONIC |
1089 | if (expect_true (have_monotonic)) |
1150 | if (expect_true (have_monotonic)) |
1090 | time_update_monotonic (EV_A); |
1151 | time_update_monotonic (EV_A); |
1091 | else |
1152 | else |
… | |
… | |
1124 | /* queue pending timers and reschedule them */ |
1185 | /* queue pending timers and reschedule them */ |
1125 | timers_reify (EV_A); /* relative timers called last */ |
1186 | timers_reify (EV_A); /* relative timers called last */ |
1126 | periodics_reify (EV_A); /* absolute timers called first */ |
1187 | periodics_reify (EV_A); /* absolute timers called first */ |
1127 | |
1188 | |
1128 | /* queue idle watchers unless io or timers are pending */ |
1189 | /* queue idle watchers unless io or timers are pending */ |
1129 | if (!pendingcnt) |
1190 | if (idlecnt && !any_pending (EV_A)) |
1130 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1191 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1131 | |
1192 | |
1132 | /* queue check watchers, to be executed first */ |
1193 | /* queue check watchers, to be executed first */ |
1133 | if (checkcnt) |
1194 | if (checkcnt) |
1134 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1195 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
… | |
… | |
1272 | ev_timer_again (EV_P_ struct ev_timer *w) |
1333 | ev_timer_again (EV_P_ struct ev_timer *w) |
1273 | { |
1334 | { |
1274 | if (ev_is_active (w)) |
1335 | if (ev_is_active (w)) |
1275 | { |
1336 | { |
1276 | if (w->repeat) |
1337 | if (w->repeat) |
1277 | { |
|
|
1278 | ((WT)w)->at = mn_now + w->repeat; |
|
|
1279 | downheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1338 | adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1, mn_now + w->repeat); |
1280 | } |
|
|
1281 | else |
1339 | else |
1282 | ev_timer_stop (EV_A_ w); |
1340 | ev_timer_stop (EV_A_ w); |
1283 | } |
1341 | } |
1284 | else if (w->repeat) |
1342 | else if (w->repeat) |
1285 | ev_timer_start (EV_A_ w); |
1343 | ev_timer_start (EV_A_ w); |
… | |
… | |
1289 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1347 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1290 | { |
1348 | { |
1291 | if (ev_is_active (w)) |
1349 | if (ev_is_active (w)) |
1292 | return; |
1350 | return; |
1293 | |
1351 | |
|
|
1352 | if (w->reschedule_cb) |
|
|
1353 | ((WT)w)->at = w->reschedule_cb (w, rt_now); |
|
|
1354 | else if (w->interval) |
|
|
1355 | { |
1294 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1356 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1295 | |
|
|
1296 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1357 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1297 | if (w->interval) |
|
|
1298 | ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1358 | ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
|
|
1359 | } |
1299 | |
1360 | |
1300 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1361 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1301 | array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, (void)); |
1362 | array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, (void)); |
1302 | periodics [periodiccnt - 1] = w; |
1363 | periodics [periodiccnt - 1] = w; |
1303 | upheap ((WT *)periodics, periodiccnt - 1); |
1364 | upheap ((WT *)periodics, periodiccnt - 1); |
… | |
… | |
1319 | periodics [((W)w)->active - 1] = periodics [periodiccnt]; |
1380 | periodics [((W)w)->active - 1] = periodics [periodiccnt]; |
1320 | downheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); |
1381 | downheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); |
1321 | } |
1382 | } |
1322 | |
1383 | |
1323 | ev_stop (EV_A_ (W)w); |
1384 | ev_stop (EV_A_ (W)w); |
|
|
1385 | } |
|
|
1386 | |
|
|
1387 | void |
|
|
1388 | ev_periodic_again (EV_P_ struct ev_periodic *w) |
|
|
1389 | { |
|
|
1390 | /* TODO: use adjustheap and recalculation */ |
|
|
1391 | ev_periodic_stop (EV_A_ w); |
|
|
1392 | ev_periodic_start (EV_A_ w); |
1324 | } |
1393 | } |
1325 | |
1394 | |
1326 | void |
1395 | void |
1327 | ev_idle_start (EV_P_ struct ev_idle *w) |
1396 | ev_idle_start (EV_P_ struct ev_idle *w) |
1328 | { |
1397 | { |
… | |
… | |
1505 | else |
1574 | else |
1506 | { |
1575 | { |
1507 | once->cb = cb; |
1576 | once->cb = cb; |
1508 | once->arg = arg; |
1577 | once->arg = arg; |
1509 | |
1578 | |
1510 | ev_watcher_init (&once->io, once_cb_io); |
1579 | ev_init (&once->io, once_cb_io); |
1511 | if (fd >= 0) |
1580 | if (fd >= 0) |
1512 | { |
1581 | { |
1513 | ev_io_set (&once->io, fd, events); |
1582 | ev_io_set (&once->io, fd, events); |
1514 | ev_io_start (EV_A_ &once->io); |
1583 | ev_io_start (EV_A_ &once->io); |
1515 | } |
1584 | } |
1516 | |
1585 | |
1517 | ev_watcher_init (&once->to, once_cb_to); |
1586 | ev_init (&once->to, once_cb_to); |
1518 | if (timeout >= 0.) |
1587 | if (timeout >= 0.) |
1519 | { |
1588 | { |
1520 | ev_timer_set (&once->to, timeout, 0.); |
1589 | ev_timer_set (&once->to, timeout, 0.); |
1521 | ev_timer_start (EV_A_ &once->to); |
1590 | ev_timer_start (EV_A_ &once->to); |
1522 | } |
1591 | } |