ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.62 by root, Sun Nov 4 20:38:07 2007 UTC vs.
Revision 1.66 by root, Sun Nov 4 23:30:53 2007 UTC

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
239static void 242static void
240anfds_init (ANFD *base, int count) 243anfds_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
534static void 534static void
637} 637}
638 638
639void 639void
640loop_destroy (EV_P) 640loop_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
804} 816}
805 817
806static void 818static void
807timers_reify (EV_P) 819timers_reify (EV_P)
808{ 820{
809 while (timercnt && timers [0]->at <= mn_now) 821 while (timercnt && ((WT)timers [0])->at <= mn_now)
810 { 822 {
811 struct ev_timer *w = timers [0]; 823 struct ev_timer *w = timers [0];
812 824
813 assert (("inactive timer on timer heap detected", ev_is_active (w))); 825 assert (("inactive timer on timer heap detected", ev_is_active (w)));
814 826
815 /* first reschedule or stop timer */ 827 /* first reschedule or stop timer */
816 if (w->repeat) 828 if (w->repeat)
817 { 829 {
818 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); 830 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.));
819 w->at = mn_now + w->repeat; 831 ((WT)w)->at = mn_now + w->repeat;
820 downheap ((WT *)timers, timercnt, 0); 832 downheap ((WT *)timers, timercnt, 0);
821 } 833 }
822 else 834 else
823 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ 835 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
824 836
827} 839}
828 840
829static void 841static void
830periodics_reify (EV_P) 842periodics_reify (EV_P)
831{ 843{
832 while (periodiccnt && periodics [0]->at <= rt_now) 844 while (periodiccnt && ((WT)periodics [0])->at <= rt_now)
833 { 845 {
834 struct ev_periodic *w = periodics [0]; 846 struct ev_periodic *w = periodics [0];
835 847
836 assert (("inactive timer on periodic heap detected", ev_is_active (w))); 848 assert (("inactive timer on periodic heap detected", ev_is_active (w)));
837 849
838 /* first reschedule or stop timer */ 850 /* first reschedule or stop timer */
839 if (w->interval) 851 if (w->interval)
840 { 852 {
841 w->at += floor ((rt_now - w->at) / w->interval + 1.) * w->interval; 853 ((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)); 854 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now));
843 downheap ((WT *)periodics, periodiccnt, 0); 855 downheap ((WT *)periodics, periodiccnt, 0);
844 } 856 }
845 else 857 else
846 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ 858 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
847 859
859 { 871 {
860 struct ev_periodic *w = periodics [i]; 872 struct ev_periodic *w = periodics [i];
861 873
862 if (w->interval) 874 if (w->interval)
863 { 875 {
864 ev_tstamp diff = ceil ((rt_now - w->at) / w->interval) * w->interval; 876 ev_tstamp diff = ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval;
865 877
866 if (fabs (diff) >= 1e-4) 878 if (fabs (diff) >= 1e-4)
867 { 879 {
868 ev_periodic_stop (EV_A_ w); 880 ev_periodic_stop (EV_A_ w);
869 ev_periodic_start (EV_A_ w); 881 ev_periodic_start (EV_A_ w);
930 { 942 {
931 periodics_reschedule (EV_A); 943 periodics_reschedule (EV_A);
932 944
933 /* adjust timers. this is easy, as the offset is the same for all */ 945 /* adjust timers. this is easy, as the offset is the same for all */
934 for (i = 0; i < timercnt; ++i) 946 for (i = 0; i < timercnt; ++i)
935 timers [i]->at += rt_now - mn_now; 947 ((WT)timers [i])->at += rt_now - mn_now;
936 } 948 }
937 949
938 mn_now = rt_now; 950 mn_now = rt_now;
939 } 951 }
940} 952}
991 { 1003 {
992 block = MAX_BLOCKTIME; 1004 block = MAX_BLOCKTIME;
993 1005
994 if (timercnt) 1006 if (timercnt)
995 { 1007 {
996 ev_tstamp to = timers [0]->at - mn_now + method_fudge; 1008 ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge;
997 if (block > to) block = to; 1009 if (block > to) block = to;
998 } 1010 }
999 1011
1000 if (periodiccnt) 1012 if (periodiccnt)
1001 { 1013 {
1002 ev_tstamp to = periodics [0]->at - rt_now + method_fudge; 1014 ev_tstamp to = ((WT)periodics [0])->at - rt_now + method_fudge;
1003 if (block > to) block = to; 1015 if (block > to) block = to;
1004 } 1016 }
1005 1017
1006 if (block < 0.) block = 0.; 1018 if (block < 0.) block = 0.;
1007 } 1019 }
1124ev_timer_start (EV_P_ struct ev_timer *w) 1136ev_timer_start (EV_P_ struct ev_timer *w)
1125{ 1137{
1126 if (ev_is_active (w)) 1138 if (ev_is_active (w))
1127 return; 1139 return;
1128 1140
1129 w->at += mn_now; 1141 ((WT)w)->at += mn_now;
1130 1142
1131 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1143 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1132 1144
1133 ev_start (EV_A_ (W)w, ++timercnt); 1145 ev_start (EV_A_ (W)w, ++timercnt);
1134 array_needsize (timers, timermax, timercnt, ); 1146 array_needsize (timers, timermax, timercnt, );
1151 { 1163 {
1152 timers [((W)w)->active - 1] = timers [timercnt]; 1164 timers [((W)w)->active - 1] = timers [timercnt];
1153 downheap ((WT *)timers, timercnt, ((W)w)->active - 1); 1165 downheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1154 } 1166 }
1155 1167
1156 w->at = w->repeat; 1168 ((WT)w)->at = w->repeat;
1157 1169
1158 ev_stop (EV_A_ (W)w); 1170 ev_stop (EV_A_ (W)w);
1159} 1171}
1160 1172
1161void 1173void
1163{ 1175{
1164 if (ev_is_active (w)) 1176 if (ev_is_active (w))
1165 { 1177 {
1166 if (w->repeat) 1178 if (w->repeat)
1167 { 1179 {
1168 w->at = mn_now + w->repeat; 1180 ((WT)w)->at = mn_now + w->repeat;
1169 downheap ((WT *)timers, timercnt, ((W)w)->active - 1); 1181 downheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1170 } 1182 }
1171 else 1183 else
1172 ev_timer_stop (EV_A_ w); 1184 ev_timer_stop (EV_A_ w);
1173 } 1185 }
1183 1195
1184 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); 1196 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.));
1185 1197
1186 /* this formula differs from the one in periodic_reify because we do not always round up */ 1198 /* this formula differs from the one in periodic_reify because we do not always round up */
1187 if (w->interval) 1199 if (w->interval)
1188 w->at += ceil ((rt_now - w->at) / w->interval) * w->interval; 1200 ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval;
1189 1201
1190 ev_start (EV_A_ (W)w, ++periodiccnt); 1202 ev_start (EV_A_ (W)w, ++periodiccnt);
1191 array_needsize (periodics, periodicmax, periodiccnt, ); 1203 array_needsize (periodics, periodicmax, periodiccnt, );
1192 periodics [periodiccnt - 1] = w; 1204 periodics [periodiccnt - 1] = w;
1193 upheap ((WT *)periodics, periodiccnt - 1); 1205 upheap ((WT *)periodics, periodiccnt - 1);
1296 1308
1297 ev_start (EV_A_ (W)w, 1); 1309 ev_start (EV_A_ (W)w, 1);
1298 array_needsize (signals, signalmax, w->signum, signals_init); 1310 array_needsize (signals, signalmax, w->signum, signals_init);
1299 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1311 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1300 1312
1301 if (!w->next) 1313 if (!((WL)w)->next)
1302 { 1314 {
1303 struct sigaction sa; 1315 struct sigaction sa;
1304 sa.sa_handler = sighandler; 1316 sa.sa_handler = sighandler;
1305 sigfillset (&sa.sa_mask); 1317 sigfillset (&sa.sa_mask);
1306 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ 1318 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines