… | |
… | |
232 | base = realloc (base, sizeof (*base) * (newcnt)); \ |
232 | base = realloc (base, sizeof (*base) * (newcnt)); \ |
233 | init (base + cur, newcnt - cur); \ |
233 | init (base + cur, newcnt - cur); \ |
234 | cur = newcnt; \ |
234 | cur = newcnt; \ |
235 | } |
235 | } |
236 | |
236 | |
|
|
237 | #define array_free(stem, idx) \ |
|
|
238 | free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
|
|
239 | |
237 | /*****************************************************************************/ |
240 | /*****************************************************************************/ |
238 | |
241 | |
239 | static void |
242 | static void |
240 | anfds_init (ANFD *base, int count) |
243 | anfds_init (ANFD *base, int count) |
241 | { |
244 | { |
… | |
… | |
306 | 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) |
307 | events |= w->events; |
310 | events |= w->events; |
308 | |
311 | |
309 | anfd->reify = 0; |
312 | anfd->reify = 0; |
310 | |
313 | |
311 | if (anfd->events != events) |
|
|
312 | { |
|
|
313 | method_modify (EV_A_ fd, anfd->events, events); |
314 | method_modify (EV_A_ fd, anfd->events, events); |
314 | anfd->events = events; |
315 | anfd->events = events; |
315 | } |
|
|
316 | } |
316 | } |
317 | |
317 | |
318 | fdchangecnt = 0; |
318 | fdchangecnt = 0; |
319 | } |
319 | } |
320 | |
320 | |
… | |
… | |
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 |
… | |
… | |
637 | } |
637 | } |
638 | |
638 | |
639 | void |
639 | void |
640 | loop_destroy (EV_P) |
640 | loop_destroy (EV_P) |
641 | { |
641 | { |
|
|
642 | int i; |
|
|
643 | |
642 | #if EV_USE_WIN32 |
644 | #if EV_USE_WIN32 |
643 | if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A); |
645 | if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A); |
644 | #endif |
646 | #endif |
645 | #if EV_USE_KQUEUE |
647 | #if EV_USE_KQUEUE |
646 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
648 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
… | |
… | |
652 | if (method == EVMETHOD_POLL ) poll_destroy (EV_A); |
654 | if (method == EVMETHOD_POLL ) poll_destroy (EV_A); |
653 | #endif |
655 | #endif |
654 | #if EV_USE_SELECT |
656 | #if EV_USE_SELECT |
655 | if (method == EVMETHOD_SELECT) select_destroy (EV_A); |
657 | if (method == EVMETHOD_SELECT) select_destroy (EV_A); |
656 | #endif |
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, ); |
657 | |
669 | |
658 | method = 0; |
670 | method = 0; |
659 | /*TODO*/ |
671 | /*TODO*/ |
660 | } |
672 | } |
661 | |
673 | |
… | |
… | |
796 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
808 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
797 | |
809 | |
798 | if (p->w) |
810 | if (p->w) |
799 | { |
811 | { |
800 | p->w->pending = 0; |
812 | p->w->pending = 0; |
|
|
813 | |
801 | p->w->cb (EV_A_ p->w, p->events); |
814 | ((void (*)(EV_P_ W, int))p->w->cb) (EV_A_ p->w, p->events); |
802 | } |
815 | } |
803 | } |
816 | } |
804 | } |
817 | } |
805 | |
818 | |
806 | static void |
819 | static void |
807 | timers_reify (EV_P) |
820 | timers_reify (EV_P) |
808 | { |
821 | { |
809 | while (timercnt && timers [0]->at <= mn_now) |
822 | while (timercnt && ((WT)timers [0])->at <= mn_now) |
810 | { |
823 | { |
811 | struct ev_timer *w = timers [0]; |
824 | struct ev_timer *w = timers [0]; |
812 | |
825 | |
813 | assert (("inactive timer on timer heap detected", ev_is_active (w))); |
826 | assert (("inactive timer on timer heap detected", ev_is_active (w))); |
814 | |
827 | |
815 | /* first reschedule or stop timer */ |
828 | /* first reschedule or stop timer */ |
816 | if (w->repeat) |
829 | if (w->repeat) |
817 | { |
830 | { |
818 | 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.)); |
819 | w->at = mn_now + w->repeat; |
832 | ((WT)w)->at = mn_now + w->repeat; |
820 | downheap ((WT *)timers, timercnt, 0); |
833 | downheap ((WT *)timers, timercnt, 0); |
821 | } |
834 | } |
822 | else |
835 | else |
823 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
836 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
824 | |
837 | |
… | |
… | |
827 | } |
840 | } |
828 | |
841 | |
829 | static void |
842 | static void |
830 | periodics_reify (EV_P) |
843 | periodics_reify (EV_P) |
831 | { |
844 | { |
832 | while (periodiccnt && periodics [0]->at <= rt_now) |
845 | while (periodiccnt && ((WT)periodics [0])->at <= rt_now) |
833 | { |
846 | { |
834 | struct ev_periodic *w = periodics [0]; |
847 | struct ev_periodic *w = periodics [0]; |
835 | |
848 | |
836 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
849 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
837 | |
850 | |
838 | /* first reschedule or stop timer */ |
851 | /* first reschedule or stop timer */ |
839 | if (w->interval) |
852 | if (w->interval) |
840 | { |
853 | { |
841 | 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; |
842 | 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)); |
843 | downheap ((WT *)periodics, periodiccnt, 0); |
856 | downheap ((WT *)periodics, periodiccnt, 0); |
844 | } |
857 | } |
845 | else |
858 | else |
846 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
859 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
847 | |
860 | |
… | |
… | |
859 | { |
872 | { |
860 | struct ev_periodic *w = periodics [i]; |
873 | struct ev_periodic *w = periodics [i]; |
861 | |
874 | |
862 | if (w->interval) |
875 | if (w->interval) |
863 | { |
876 | { |
864 | 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; |
865 | |
878 | |
866 | if (fabs (diff) >= 1e-4) |
879 | if (fabs (diff) >= 1e-4) |
867 | { |
880 | { |
868 | ev_periodic_stop (EV_A_ w); |
881 | ev_periodic_stop (EV_A_ w); |
869 | ev_periodic_start (EV_A_ w); |
882 | ev_periodic_start (EV_A_ w); |
… | |
… | |
930 | { |
943 | { |
931 | periodics_reschedule (EV_A); |
944 | periodics_reschedule (EV_A); |
932 | |
945 | |
933 | /* 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 */ |
934 | for (i = 0; i < timercnt; ++i) |
947 | for (i = 0; i < timercnt; ++i) |
935 | timers [i]->at += rt_now - mn_now; |
948 | ((WT)timers [i])->at += rt_now - mn_now; |
936 | } |
949 | } |
937 | |
950 | |
938 | mn_now = rt_now; |
951 | mn_now = rt_now; |
939 | } |
952 | } |
940 | } |
953 | } |
… | |
… | |
991 | { |
1004 | { |
992 | block = MAX_BLOCKTIME; |
1005 | block = MAX_BLOCKTIME; |
993 | |
1006 | |
994 | if (timercnt) |
1007 | if (timercnt) |
995 | { |
1008 | { |
996 | ev_tstamp to = timers [0]->at - mn_now + method_fudge; |
1009 | ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge; |
997 | if (block > to) block = to; |
1010 | if (block > to) block = to; |
998 | } |
1011 | } |
999 | |
1012 | |
1000 | if (periodiccnt) |
1013 | if (periodiccnt) |
1001 | { |
1014 | { |
1002 | ev_tstamp to = periodics [0]->at - rt_now + method_fudge; |
1015 | ev_tstamp to = ((WT)periodics [0])->at - rt_now + method_fudge; |
1003 | if (block > to) block = to; |
1016 | if (block > to) block = to; |
1004 | } |
1017 | } |
1005 | |
1018 | |
1006 | if (block < 0.) block = 0.; |
1019 | if (block < 0.) block = 0.; |
1007 | } |
1020 | } |
… | |
… | |
1124 | ev_timer_start (EV_P_ struct ev_timer *w) |
1137 | ev_timer_start (EV_P_ struct ev_timer *w) |
1125 | { |
1138 | { |
1126 | if (ev_is_active (w)) |
1139 | if (ev_is_active (w)) |
1127 | return; |
1140 | return; |
1128 | |
1141 | |
1129 | w->at += mn_now; |
1142 | ((WT)w)->at += mn_now; |
1130 | |
1143 | |
1131 | 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.)); |
1132 | |
1145 | |
1133 | ev_start (EV_A_ (W)w, ++timercnt); |
1146 | ev_start (EV_A_ (W)w, ++timercnt); |
1134 | array_needsize (timers, timermax, timercnt, ); |
1147 | array_needsize (timers, timermax, timercnt, ); |
… | |
… | |
1151 | { |
1164 | { |
1152 | timers [((W)w)->active - 1] = timers [timercnt]; |
1165 | timers [((W)w)->active - 1] = timers [timercnt]; |
1153 | downheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1166 | downheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1154 | } |
1167 | } |
1155 | |
1168 | |
1156 | w->at = w->repeat; |
1169 | ((WT)w)->at = w->repeat; |
1157 | |
1170 | |
1158 | ev_stop (EV_A_ (W)w); |
1171 | ev_stop (EV_A_ (W)w); |
1159 | } |
1172 | } |
1160 | |
1173 | |
1161 | void |
1174 | void |
… | |
… | |
1163 | { |
1176 | { |
1164 | if (ev_is_active (w)) |
1177 | if (ev_is_active (w)) |
1165 | { |
1178 | { |
1166 | if (w->repeat) |
1179 | if (w->repeat) |
1167 | { |
1180 | { |
1168 | w->at = mn_now + w->repeat; |
1181 | ((WT)w)->at = mn_now + w->repeat; |
1169 | downheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1182 | downheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1170 | } |
1183 | } |
1171 | else |
1184 | else |
1172 | ev_timer_stop (EV_A_ w); |
1185 | ev_timer_stop (EV_A_ w); |
1173 | } |
1186 | } |
… | |
… | |
1183 | |
1196 | |
1184 | 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.)); |
1185 | |
1198 | |
1186 | /* 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 */ |
1187 | if (w->interval) |
1200 | if (w->interval) |
1188 | 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; |
1189 | |
1202 | |
1190 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1203 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1191 | array_needsize (periodics, periodicmax, periodiccnt, ); |
1204 | array_needsize (periodics, periodicmax, periodiccnt, ); |
1192 | periodics [periodiccnt - 1] = w; |
1205 | periodics [periodiccnt - 1] = w; |
1193 | upheap ((WT *)periodics, periodiccnt - 1); |
1206 | upheap ((WT *)periodics, periodiccnt - 1); |
… | |
… | |
1296 | |
1309 | |
1297 | ev_start (EV_A_ (W)w, 1); |
1310 | ev_start (EV_A_ (W)w, 1); |
1298 | array_needsize (signals, signalmax, w->signum, signals_init); |
1311 | array_needsize (signals, signalmax, w->signum, signals_init); |
1299 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1312 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1300 | |
1313 | |
1301 | if (!w->next) |
1314 | if (!((WL)w)->next) |
1302 | { |
1315 | { |
1303 | struct sigaction sa; |
1316 | struct sigaction sa; |
1304 | sa.sa_handler = sighandler; |
1317 | sa.sa_handler = sighandler; |
1305 | sigfillset (&sa.sa_mask); |
1318 | sigfillset (&sa.sa_mask); |
1306 | 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 */ |