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