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

Comparing libev/ev.c (file contents):
Revision 1.112 by root, Mon Nov 12 07:20:24 2007 UTC vs.
Revision 1.115 by root, Wed Nov 14 04:53:21 2007 UTC

167#define expect_true(expr) expect ((expr) != 0, 1) 167#define expect_true(expr) expect ((expr) != 0, 1)
168 168
169#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) 169#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
170#define ABSPRI(w) ((w)->priority - EV_MINPRI) 170#define ABSPRI(w) ((w)->priority - EV_MINPRI)
171 171
172#define EMPTY /* required for microsofts broken pseudo-c compiler */ 172#define EMPTY0 /* required for microsofts broken pseudo-c compiler */
173#define EMPTY2(a,b) /* used to suppress some warnings */
173 174
174typedef struct ev_watcher *W; 175typedef struct ev_watcher *W;
175typedef struct ev_watcher_list *WL; 176typedef struct ev_watcher_list *WL;
176typedef struct ev_watcher_time *WT; 177typedef struct ev_watcher_time *WT;
177 178
365 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; 366 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents;
366 return; 367 return;
367 } 368 }
368 369
369 w_->pending = ++pendingcnt [ABSPRI (w_)]; 370 w_->pending = ++pendingcnt [ABSPRI (w_)];
370 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], (void)); 371 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2);
371 pendings [ABSPRI (w_)][w_->pending - 1].w = w_; 372 pendings [ABSPRI (w_)][w_->pending - 1].w = w_;
372 pendings [ABSPRI (w_)][w_->pending - 1].events = revents; 373 pendings [ABSPRI (w_)][w_->pending - 1].events = revents;
373} 374}
374 375
375static void 376static void
445 return; 446 return;
446 447
447 anfds [fd].reify = 1; 448 anfds [fd].reify = 1;
448 449
449 ++fdchangecnt; 450 ++fdchangecnt;
450 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, (void)); 451 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2);
451 fdchanges [fdchangecnt - 1] = fd; 452 fdchanges [fdchangecnt - 1] = fd;
452} 453}
453 454
454static void 455static void
455fd_kill (EV_P_ int fd) 456fd_kill (EV_P_ int fd)
770 ev_rt_now = ev_time (); 771 ev_rt_now = ev_time ();
771 mn_now = get_clock (); 772 mn_now = get_clock ();
772 now_floor = mn_now; 773 now_floor = mn_now;
773 rtmn_diff = ev_rt_now - mn_now; 774 rtmn_diff = ev_rt_now - mn_now;
774 775
775 if (!(flags & EVMETHOD_NOENV) && !enable_secure () && getenv ("LIBEV_FLAGS")) 776 if (!(flags & EVFLAG_NOENV) && !enable_secure () && getenv ("LIBEV_FLAGS"))
776 flags = atoi (getenv ("LIBEV_FLAGS")); 777 flags = atoi (getenv ("LIBEV_FLAGS"));
777 778
778 if (!(flags & 0x0000ffff)) 779 if (!(flags & 0x0000ffff))
779 flags |= 0x0000ffff; 780 flags |= 0x0000ffff;
780 781
817 818
818 for (i = NUMPRI; i--; ) 819 for (i = NUMPRI; i--; )
819 array_free (pending, [i]); 820 array_free (pending, [i]);
820 821
821 /* have to use the microsoft-never-gets-it-right macro */ 822 /* have to use the microsoft-never-gets-it-right macro */
822 array_free (fdchange, EMPTY); 823 array_free (fdchange, EMPTY0);
823 array_free (timer, EMPTY); 824 array_free (timer, EMPTY0);
824#if EV_PERIODICS 825#if EV_PERIODICS
825 array_free (periodic, EMPTY); 826 array_free (periodic, EMPTY0);
826#endif 827#endif
827 array_free (idle, EMPTY); 828 array_free (idle, EMPTY0);
828 array_free (prepare, EMPTY); 829 array_free (prepare, EMPTY0);
829 array_free (check, EMPTY); 830 array_free (check, EMPTY0);
830 831
831 method = 0; 832 method = 0;
832} 833}
833 834
834static void 835static void
1159ev_loop (EV_P_ int flags) 1160ev_loop (EV_P_ int flags)
1160{ 1161{
1161 double block; 1162 double block;
1162 loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0; 1163 loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0;
1163 1164
1164 do 1165 while (activecnt)
1165 { 1166 {
1166 /* queue check watchers (and execute them) */ 1167 /* queue check watchers (and execute them) */
1167 if (expect_false (preparecnt)) 1168 if (expect_false (preparecnt))
1168 { 1169 {
1169 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 1170 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
1232 /* queue check watchers, to be executed first */ 1233 /* queue check watchers, to be executed first */
1233 if (checkcnt) 1234 if (checkcnt)
1234 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 1235 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
1235 1236
1236 call_pending (EV_A); 1237 call_pending (EV_A);
1238
1239 if (loop_done)
1240 break;
1237 } 1241 }
1238 while (activecnt && !loop_done);
1239 1242
1240 if (loop_done != 2) 1243 if (loop_done != 2)
1241 loop_done = 0; 1244 loop_done = 0;
1242} 1245}
1243 1246
1341 ((WT)w)->at += mn_now; 1344 ((WT)w)->at += mn_now;
1342 1345
1343 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1346 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1344 1347
1345 ev_start (EV_A_ (W)w, ++timercnt); 1348 ev_start (EV_A_ (W)w, ++timercnt);
1346 array_needsize (struct ev_timer *, timers, timermax, timercnt, (void)); 1349 array_needsize (struct ev_timer *, timers, timermax, timercnt, EMPTY2);
1347 timers [timercnt - 1] = w; 1350 timers [timercnt - 1] = w;
1348 upheap ((WT *)timers, timercnt - 1); 1351 upheap ((WT *)timers, timercnt - 1);
1349 1352
1350 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1353 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1351} 1354}
1405 /* this formula differs from the one in periodic_reify because we do not always round up */ 1408 /* this formula differs from the one in periodic_reify because we do not always round up */
1406 ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; 1409 ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval;
1407 } 1410 }
1408 1411
1409 ev_start (EV_A_ (W)w, ++periodiccnt); 1412 ev_start (EV_A_ (W)w, ++periodiccnt);
1410 array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, (void)); 1413 array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2);
1411 periodics [periodiccnt - 1] = w; 1414 periodics [periodiccnt - 1] = w;
1412 upheap ((WT *)periodics, periodiccnt - 1); 1415 upheap ((WT *)periodics, periodiccnt - 1);
1413 1416
1414 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1417 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1415} 1418}
1446{ 1449{
1447 if (ev_is_active (w)) 1450 if (ev_is_active (w))
1448 return; 1451 return;
1449 1452
1450 ev_start (EV_A_ (W)w, ++idlecnt); 1453 ev_start (EV_A_ (W)w, ++idlecnt);
1451 array_needsize (struct ev_idle *, idles, idlemax, idlecnt, (void)); 1454 array_needsize (struct ev_idle *, idles, idlemax, idlecnt, EMPTY2);
1452 idles [idlecnt - 1] = w; 1455 idles [idlecnt - 1] = w;
1453} 1456}
1454 1457
1455void 1458void
1456ev_idle_stop (EV_P_ struct ev_idle *w) 1459ev_idle_stop (EV_P_ struct ev_idle *w)
1468{ 1471{
1469 if (ev_is_active (w)) 1472 if (ev_is_active (w))
1470 return; 1473 return;
1471 1474
1472 ev_start (EV_A_ (W)w, ++preparecnt); 1475 ev_start (EV_A_ (W)w, ++preparecnt);
1473 array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, (void)); 1476 array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, EMPTY2);
1474 prepares [preparecnt - 1] = w; 1477 prepares [preparecnt - 1] = w;
1475} 1478}
1476 1479
1477void 1480void
1478ev_prepare_stop (EV_P_ struct ev_prepare *w) 1481ev_prepare_stop (EV_P_ struct ev_prepare *w)
1490{ 1493{
1491 if (ev_is_active (w)) 1494 if (ev_is_active (w))
1492 return; 1495 return;
1493 1496
1494 ev_start (EV_A_ (W)w, ++checkcnt); 1497 ev_start (EV_A_ (W)w, ++checkcnt);
1495 array_needsize (struct ev_check *, checks, checkmax, checkcnt, (void)); 1498 array_needsize (struct ev_check *, checks, checkmax, checkcnt, EMPTY2);
1496 checks [checkcnt - 1] = w; 1499 checks [checkcnt - 1] = w;
1497} 1500}
1498 1501
1499void 1502void
1500ev_check_stop (EV_P_ struct ev_check *w) 1503ev_check_stop (EV_P_ struct ev_check *w)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines