… | |
… | |
522 | struct ev_child *w; |
522 | struct ev_child *w; |
523 | |
523 | |
524 | 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) |
525 | if (w->pid == pid || !w->pid) |
525 | if (w->pid == pid || !w->pid) |
526 | { |
526 | { |
527 | w->priority = sw->priority; /* need to do it *now* */ |
527 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
528 | w->rpid = pid; |
528 | w->rpid = pid; |
529 | w->rstatus = status; |
529 | w->rstatus = status; |
530 | event (EV_A_ (W)w, EV_CHILD); |
530 | event (EV_A_ (W)w, EV_CHILD); |
531 | } |
531 | } |
532 | } |
532 | } |
533 | |
533 | |
534 | static void |
534 | static void |
… | |
… | |
796 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
796 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
797 | |
797 | |
798 | if (p->w) |
798 | if (p->w) |
799 | { |
799 | { |
800 | p->w->pending = 0; |
800 | p->w->pending = 0; |
|
|
801 | |
801 | p->w->cb (EV_A_ p->w, p->events); |
802 | (*(void (**)(EV_P_ W, int))&p->w->cb) (EV_A_ p->w, p->events); |
802 | } |
803 | } |
803 | } |
804 | } |
804 | } |
805 | } |
805 | |
806 | |
806 | static void |
807 | static void |
807 | timers_reify (EV_P) |
808 | timers_reify (EV_P) |
808 | { |
809 | { |
809 | while (timercnt && timers [0]->at <= mn_now) |
810 | while (timercnt && ((WT)timers [0])->at <= mn_now) |
810 | { |
811 | { |
811 | struct ev_timer *w = timers [0]; |
812 | struct ev_timer *w = timers [0]; |
812 | |
813 | |
813 | assert (("inactive timer on timer heap detected", ev_is_active (w))); |
814 | assert (("inactive timer on timer heap detected", ev_is_active (w))); |
814 | |
815 | |
815 | /* first reschedule or stop timer */ |
816 | /* first reschedule or stop timer */ |
816 | if (w->repeat) |
817 | if (w->repeat) |
817 | { |
818 | { |
818 | assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); |
819 | assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); |
819 | w->at = mn_now + w->repeat; |
820 | ((WT)w)->at = mn_now + w->repeat; |
820 | downheap ((WT *)timers, timercnt, 0); |
821 | downheap ((WT *)timers, timercnt, 0); |
821 | } |
822 | } |
822 | else |
823 | else |
823 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
824 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
824 | |
825 | |
… | |
… | |
827 | } |
828 | } |
828 | |
829 | |
829 | static void |
830 | static void |
830 | periodics_reify (EV_P) |
831 | periodics_reify (EV_P) |
831 | { |
832 | { |
832 | while (periodiccnt && periodics [0]->at <= rt_now) |
833 | while (periodiccnt && ((WT)periodics [0])->at <= rt_now) |
833 | { |
834 | { |
834 | struct ev_periodic *w = periodics [0]; |
835 | struct ev_periodic *w = periodics [0]; |
835 | |
836 | |
836 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
837 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
837 | |
838 | |
838 | /* first reschedule or stop timer */ |
839 | /* first reschedule or stop timer */ |
839 | if (w->interval) |
840 | if (w->interval) |
840 | { |
841 | { |
841 | w->at += floor ((rt_now - w->at) / w->interval + 1.) * w->interval; |
842 | ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; |
842 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", w->at > rt_now)); |
843 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now)); |
843 | downheap ((WT *)periodics, periodiccnt, 0); |
844 | downheap ((WT *)periodics, periodiccnt, 0); |
844 | } |
845 | } |
845 | else |
846 | else |
846 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
847 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
847 | |
848 | |
… | |
… | |
859 | { |
860 | { |
860 | struct ev_periodic *w = periodics [i]; |
861 | struct ev_periodic *w = periodics [i]; |
861 | |
862 | |
862 | if (w->interval) |
863 | if (w->interval) |
863 | { |
864 | { |
864 | ev_tstamp diff = ceil ((rt_now - w->at) / w->interval) * w->interval; |
865 | ev_tstamp diff = ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
865 | |
866 | |
866 | if (fabs (diff) >= 1e-4) |
867 | if (fabs (diff) >= 1e-4) |
867 | { |
868 | { |
868 | ev_periodic_stop (EV_A_ w); |
869 | ev_periodic_stop (EV_A_ w); |
869 | ev_periodic_start (EV_A_ w); |
870 | ev_periodic_start (EV_A_ w); |
… | |
… | |
930 | { |
931 | { |
931 | periodics_reschedule (EV_A); |
932 | periodics_reschedule (EV_A); |
932 | |
933 | |
933 | /* adjust timers. this is easy, as the offset is the same for all */ |
934 | /* adjust timers. this is easy, as the offset is the same for all */ |
934 | for (i = 0; i < timercnt; ++i) |
935 | for (i = 0; i < timercnt; ++i) |
935 | timers [i]->at += rt_now - mn_now; |
936 | ((WT)timers [i])->at += rt_now - mn_now; |
936 | } |
937 | } |
937 | |
938 | |
938 | mn_now = rt_now; |
939 | mn_now = rt_now; |
939 | } |
940 | } |
940 | } |
941 | } |
… | |
… | |
991 | { |
992 | { |
992 | block = MAX_BLOCKTIME; |
993 | block = MAX_BLOCKTIME; |
993 | |
994 | |
994 | if (timercnt) |
995 | if (timercnt) |
995 | { |
996 | { |
996 | ev_tstamp to = timers [0]->at - mn_now + method_fudge; |
997 | ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge; |
997 | if (block > to) block = to; |
998 | if (block > to) block = to; |
998 | } |
999 | } |
999 | |
1000 | |
1000 | if (periodiccnt) |
1001 | if (periodiccnt) |
1001 | { |
1002 | { |
1002 | ev_tstamp to = periodics [0]->at - rt_now + method_fudge; |
1003 | ev_tstamp to = ((WT)periodics [0])->at - rt_now + method_fudge; |
1003 | if (block > to) block = to; |
1004 | if (block > to) block = to; |
1004 | } |
1005 | } |
1005 | |
1006 | |
1006 | if (block < 0.) block = 0.; |
1007 | if (block < 0.) block = 0.; |
1007 | } |
1008 | } |
… | |
… | |
1124 | ev_timer_start (EV_P_ struct ev_timer *w) |
1125 | ev_timer_start (EV_P_ struct ev_timer *w) |
1125 | { |
1126 | { |
1126 | if (ev_is_active (w)) |
1127 | if (ev_is_active (w)) |
1127 | return; |
1128 | return; |
1128 | |
1129 | |
1129 | w->at += mn_now; |
1130 | ((WT)w)->at += mn_now; |
1130 | |
1131 | |
1131 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1132 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1132 | |
1133 | |
1133 | ev_start (EV_A_ (W)w, ++timercnt); |
1134 | ev_start (EV_A_ (W)w, ++timercnt); |
1134 | array_needsize (timers, timermax, timercnt, ); |
1135 | array_needsize (timers, timermax, timercnt, ); |
… | |
… | |
1151 | { |
1152 | { |
1152 | timers [((W)w)->active - 1] = timers [timercnt]; |
1153 | timers [((W)w)->active - 1] = timers [timercnt]; |
1153 | downheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1154 | downheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1154 | } |
1155 | } |
1155 | |
1156 | |
1156 | w->at = w->repeat; |
1157 | ((WT)w)->at = w->repeat; |
1157 | |
1158 | |
1158 | ev_stop (EV_A_ (W)w); |
1159 | ev_stop (EV_A_ (W)w); |
1159 | } |
1160 | } |
1160 | |
1161 | |
1161 | void |
1162 | void |
… | |
… | |
1163 | { |
1164 | { |
1164 | if (ev_is_active (w)) |
1165 | if (ev_is_active (w)) |
1165 | { |
1166 | { |
1166 | if (w->repeat) |
1167 | if (w->repeat) |
1167 | { |
1168 | { |
1168 | w->at = mn_now + w->repeat; |
1169 | ((WT)w)->at = mn_now + w->repeat; |
1169 | downheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1170 | downheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1170 | } |
1171 | } |
1171 | else |
1172 | else |
1172 | ev_timer_stop (EV_A_ w); |
1173 | ev_timer_stop (EV_A_ w); |
1173 | } |
1174 | } |
… | |
… | |
1183 | |
1184 | |
1184 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1185 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1185 | |
1186 | |
1186 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1187 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1187 | if (w->interval) |
1188 | if (w->interval) |
1188 | w->at += ceil ((rt_now - w->at) / w->interval) * w->interval; |
1189 | ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1189 | |
1190 | |
1190 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1191 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1191 | array_needsize (periodics, periodicmax, periodiccnt, ); |
1192 | array_needsize (periodics, periodicmax, periodiccnt, ); |
1192 | periodics [periodiccnt - 1] = w; |
1193 | periodics [periodiccnt - 1] = w; |
1193 | upheap ((WT *)periodics, periodiccnt - 1); |
1194 | upheap ((WT *)periodics, periodiccnt - 1); |
… | |
… | |
1296 | |
1297 | |
1297 | ev_start (EV_A_ (W)w, 1); |
1298 | ev_start (EV_A_ (W)w, 1); |
1298 | array_needsize (signals, signalmax, w->signum, signals_init); |
1299 | array_needsize (signals, signalmax, w->signum, signals_init); |
1299 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1300 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1300 | |
1301 | |
1301 | if (!w->next) |
1302 | if (!((WL)w)->next) |
1302 | { |
1303 | { |
1303 | struct sigaction sa; |
1304 | struct sigaction sa; |
1304 | sa.sa_handler = sighandler; |
1305 | sa.sa_handler = sighandler; |
1305 | sigfillset (&sa.sa_mask); |
1306 | sigfillset (&sa.sa_mask); |
1306 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
1307 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |