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

Comparing libev/ev.c (file contents):
Revision 1.61 by root, Sun Nov 4 19:45:09 2007 UTC vs.
Revision 1.62 by root, Sun Nov 4 20:38:07 2007 UTC

92 92
93#ifndef EV_USE_KQUEUE 93#ifndef EV_USE_KQUEUE
94# define EV_USE_KQUEUE 0 94# define EV_USE_KQUEUE 0
95#endif 95#endif
96 96
97#ifndef EV_USE_WIN32
98# ifdef WIN32
99# define EV_USE_WIN32 1
100# else
101# define EV_USE_WIN32 0
102# endif
103#endif
104
97#ifndef EV_USE_REALTIME 105#ifndef EV_USE_REALTIME
98# define EV_USE_REALTIME 1 106# define EV_USE_REALTIME 1
99#endif 107#endif
100 108
101/**/ 109/**/
349 357
350/* called on ENOMEM in select/poll to kill some fds and retry */ 358/* called on ENOMEM in select/poll to kill some fds and retry */
351static void 359static void
352fd_enomem (EV_P) 360fd_enomem (EV_P)
353{ 361{
354 int fd = anfdmax; 362 int fd;
355 363
356 while (fd--) 364 for (fd = anfdmax; fd--; )
357 if (anfds [fd].events) 365 if (anfds [fd].events)
358 { 366 {
359 close (fd); 367 close (fd);
360 fd_kill (EV_A_ fd); 368 fd_kill (EV_A_ fd);
361 return; 369 return;
385 WT w = heap [k]; 393 WT w = heap [k];
386 394
387 while (k && heap [k >> 1]->at > w->at) 395 while (k && heap [k >> 1]->at > w->at)
388 { 396 {
389 heap [k] = heap [k >> 1]; 397 heap [k] = heap [k >> 1];
390 heap [k]->active = k + 1; 398 ((W)heap [k])->active = k + 1;
391 k >>= 1; 399 k >>= 1;
392 } 400 }
393 401
394 heap [k] = w; 402 heap [k] = w;
395 heap [k]->active = k + 1; 403 ((W)heap [k])->active = k + 1;
396 404
397} 405}
398 406
399static void 407static void
400downheap (WT *heap, int N, int k) 408downheap (WT *heap, int N, int k)
410 418
411 if (w->at <= heap [j]->at) 419 if (w->at <= heap [j]->at)
412 break; 420 break;
413 421
414 heap [k] = heap [j]; 422 heap [k] = heap [j];
415 heap [k]->active = k + 1; 423 ((W)heap [k])->active = k + 1;
416 k = j; 424 k = j;
417 } 425 }
418 426
419 heap [k] = w; 427 heap [k] = w;
420 heap [k]->active = k + 1; 428 ((W)heap [k])->active = k + 1;
421} 429}
422 430
423/*****************************************************************************/ 431/*****************************************************************************/
424 432
425typedef struct 433typedef struct
608 methods = atoi (getenv ("LIBEV_METHODS")); 616 methods = atoi (getenv ("LIBEV_METHODS"));
609 else 617 else
610 methods = EVMETHOD_ANY; 618 methods = EVMETHOD_ANY;
611 619
612 method = 0; 620 method = 0;
621#if EV_USE_WIN32
622 if (!method && (methods & EVMETHOD_WIN32 )) method = win32_init (EV_A_ methods);
623#endif
613#if EV_USE_KQUEUE 624#if EV_USE_KQUEUE
614 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); 625 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods);
615#endif 626#endif
616#if EV_USE_EPOLL 627#if EV_USE_EPOLL
617 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); 628 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods);
626} 637}
627 638
628void 639void
629loop_destroy (EV_P) 640loop_destroy (EV_P)
630{ 641{
642#if EV_USE_WIN32
643 if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A);
644#endif
631#if EV_USE_KQUEUE 645#if EV_USE_KQUEUE
632 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 646 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
633#endif 647#endif
634#if EV_USE_EPOLL 648#if EV_USE_EPOLL
635 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); 649 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A);
1118 1132
1119 ev_start (EV_A_ (W)w, ++timercnt); 1133 ev_start (EV_A_ (W)w, ++timercnt);
1120 array_needsize (timers, timermax, timercnt, ); 1134 array_needsize (timers, timermax, timercnt, );
1121 timers [timercnt - 1] = w; 1135 timers [timercnt - 1] = w;
1122 upheap ((WT *)timers, timercnt - 1); 1136 upheap ((WT *)timers, timercnt - 1);
1137
1138 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1123} 1139}
1124 1140
1125void 1141void
1126ev_timer_stop (EV_P_ struct ev_timer *w) 1142ev_timer_stop (EV_P_ struct ev_timer *w)
1127{ 1143{
1128 ev_clear_pending (EV_A_ (W)w); 1144 ev_clear_pending (EV_A_ (W)w);
1129 if (!ev_is_active (w)) 1145 if (!ev_is_active (w))
1130 return; 1146 return;
1131 1147
1148 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1149
1132 if (w->active < timercnt--) 1150 if (((W)w)->active < timercnt--)
1133 { 1151 {
1134 timers [w->active - 1] = timers [timercnt]; 1152 timers [((W)w)->active - 1] = timers [timercnt];
1135 downheap ((WT *)timers, timercnt, w->active - 1); 1153 downheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1136 } 1154 }
1137 1155
1138 w->at = w->repeat; 1156 w->at = w->repeat;
1139 1157
1140 ev_stop (EV_A_ (W)w); 1158 ev_stop (EV_A_ (W)w);
1146 if (ev_is_active (w)) 1164 if (ev_is_active (w))
1147 { 1165 {
1148 if (w->repeat) 1166 if (w->repeat)
1149 { 1167 {
1150 w->at = mn_now + w->repeat; 1168 w->at = mn_now + w->repeat;
1151 downheap ((WT *)timers, timercnt, w->active - 1); 1169 downheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1152 } 1170 }
1153 else 1171 else
1154 ev_timer_stop (EV_A_ w); 1172 ev_timer_stop (EV_A_ w);
1155 } 1173 }
1156 else if (w->repeat) 1174 else if (w->repeat)
1171 1189
1172 ev_start (EV_A_ (W)w, ++periodiccnt); 1190 ev_start (EV_A_ (W)w, ++periodiccnt);
1173 array_needsize (periodics, periodicmax, periodiccnt, ); 1191 array_needsize (periodics, periodicmax, periodiccnt, );
1174 periodics [periodiccnt - 1] = w; 1192 periodics [periodiccnt - 1] = w;
1175 upheap ((WT *)periodics, periodiccnt - 1); 1193 upheap ((WT *)periodics, periodiccnt - 1);
1194
1195 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1176} 1196}
1177 1197
1178void 1198void
1179ev_periodic_stop (EV_P_ struct ev_periodic *w) 1199ev_periodic_stop (EV_P_ struct ev_periodic *w)
1180{ 1200{
1181 ev_clear_pending (EV_A_ (W)w); 1201 ev_clear_pending (EV_A_ (W)w);
1182 if (!ev_is_active (w)) 1202 if (!ev_is_active (w))
1183 return; 1203 return;
1184 1204
1205 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1206
1185 if (w->active < periodiccnt--) 1207 if (((W)w)->active < periodiccnt--)
1186 { 1208 {
1187 periodics [w->active - 1] = periodics [periodiccnt]; 1209 periodics [((W)w)->active - 1] = periodics [periodiccnt];
1188 downheap ((WT *)periodics, periodiccnt, w->active - 1); 1210 downheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1);
1189 } 1211 }
1190 1212
1191 ev_stop (EV_A_ (W)w); 1213 ev_stop (EV_A_ (W)w);
1192} 1214}
1193 1215
1207{ 1229{
1208 ev_clear_pending (EV_A_ (W)w); 1230 ev_clear_pending (EV_A_ (W)w);
1209 if (ev_is_active (w)) 1231 if (ev_is_active (w))
1210 return; 1232 return;
1211 1233
1212 idles [w->active - 1] = idles [--idlecnt]; 1234 idles [((W)w)->active - 1] = idles [--idlecnt];
1213 ev_stop (EV_A_ (W)w); 1235 ev_stop (EV_A_ (W)w);
1214} 1236}
1215 1237
1216void 1238void
1217ev_prepare_start (EV_P_ struct ev_prepare *w) 1239ev_prepare_start (EV_P_ struct ev_prepare *w)
1229{ 1251{
1230 ev_clear_pending (EV_A_ (W)w); 1252 ev_clear_pending (EV_A_ (W)w);
1231 if (ev_is_active (w)) 1253 if (ev_is_active (w))
1232 return; 1254 return;
1233 1255
1234 prepares [w->active - 1] = prepares [--preparecnt]; 1256 prepares [((W)w)->active - 1] = prepares [--preparecnt];
1235 ev_stop (EV_A_ (W)w); 1257 ev_stop (EV_A_ (W)w);
1236} 1258}
1237 1259
1238void 1260void
1239ev_check_start (EV_P_ struct ev_check *w) 1261ev_check_start (EV_P_ struct ev_check *w)
1251{ 1273{
1252 ev_clear_pending (EV_A_ (W)w); 1274 ev_clear_pending (EV_A_ (W)w);
1253 if (ev_is_active (w)) 1275 if (ev_is_active (w))
1254 return; 1276 return;
1255 1277
1256 checks [w->active - 1] = checks [--checkcnt]; 1278 checks [((W)w)->active - 1] = checks [--checkcnt];
1257 ev_stop (EV_A_ (W)w); 1279 ev_stop (EV_A_ (W)w);
1258} 1280}
1259 1281
1260#ifndef SA_RESTART 1282#ifndef SA_RESTART
1261# define SA_RESTART 0 1283# define SA_RESTART 0

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines