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

Comparing libev/ev.c (file contents):
Revision 1.227 by root, Fri May 2 07:20:01 2008 UTC vs.
Revision 1.234 by root, Tue May 6 23:42:16 2008 UTC

325 325
326typedef ev_watcher *W; 326typedef ev_watcher *W;
327typedef ev_watcher_list *WL; 327typedef ev_watcher_list *WL;
328typedef ev_watcher_time *WT; 328typedef ev_watcher_time *WT;
329 329
330#define ev_active(w) ((W)(w))->active
331#define ev_at(w) ((WT)(w))->at
332
330#if EV_USE_MONOTONIC 333#if EV_USE_MONOTONIC
331/* sig_atomic_t is used to avoid per-thread variables or locking but still */ 334/* sig_atomic_t is used to avoid per-thread variables or locking but still */
332/* giving it a reasonably high chance of working on typical architetcures */ 335/* giving it a reasonably high chance of working on typical architetcures */
333static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 336static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
334#endif 337#endif
517 } 520 }
518} 521}
519 522
520/*****************************************************************************/ 523/*****************************************************************************/
521 524
525#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */
526
522int inline_size 527int inline_size
523array_nextsize (int elem, int cur, int cnt) 528array_nextsize (int elem, int cur, int cnt)
524{ 529{
525 int ncur = cur + 1; 530 int ncur = cur + 1;
526 531
527 do 532 do
528 ncur <<= 1; 533 ncur <<= 1;
529 while (cnt > ncur); 534 while (cnt > ncur);
530 535
531 /* if size > 4096, round to 4096 - 4 * longs to accomodate malloc overhead */ 536 /* if size is large, round to MALLOC_ROUND - 4 * longs to accomodate malloc overhead */
532 if (elem * ncur > 4096) 537 if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4)
533 { 538 {
534 ncur *= elem; 539 ncur *= elem;
535 ncur = (ncur + elem + 4095 + sizeof (void *) * 4) & ~4095; 540 ncur = (ncur + elem + (MALLOC_ROUND - 1) + sizeof (void *) * 4) & ~(MALLOC_ROUND - 1);
536 ncur = ncur - sizeof (void *) * 4; 541 ncur = ncur - sizeof (void *) * 4;
537 ncur /= elem; 542 ncur /= elem;
538 } 543 }
539 544
540 return ncur; 545 return ncur;
760void inline_speed 765void inline_speed
761upheap (WT *heap, int k) 766upheap (WT *heap, int k)
762{ 767{
763 WT w = heap [k]; 768 WT w = heap [k];
764 769
765 while (k) 770 for (;;)
766 { 771 {
767 int p = (k - 1) >> 1; 772 int p = k >> 1;
768 773
774 /* maybe we could use a dummy element at heap [0]? */
769 if (heap [p]->at <= w->at) 775 if (!p || heap [p]->at <= w->at)
770 break; 776 break;
771 777
772 heap [k] = heap [p]; 778 heap [k] = heap [p];
773 ((W)heap [k])->active = k + 1; 779 ev_active (heap [k]) = k;
774 k = p; 780 k = p;
775 } 781 }
776 782
777 heap [k] = w; 783 heap [k] = w;
778 ((W)heap [k])->active = k + 1; 784 ev_active (heap [k]) = k;
779} 785}
780 786
781/* away from the root */ 787/* away from the root */
782void inline_speed 788void inline_speed
783downheap (WT *heap, int N, int k) 789downheap (WT *heap, int N, int k)
784{ 790{
785 WT w = heap [k]; 791 WT w = heap [k];
786 792
787 for (;;) 793 for (;;)
788 { 794 {
789 int c = (k << 1) + 1; 795 int c = k << 1;
790 796
791 if (c >= N) 797 if (c > N)
792 break; 798 break;
793 799
794 c += c + 1 < N && heap [c]->at > heap [c + 1]->at 800 c += c < N && heap [c]->at > heap [c + 1]->at
795 ? 1 : 0; 801 ? 1 : 0;
796 802
797 if (w->at <= heap [c]->at) 803 if (w->at <= heap [c]->at)
798 break; 804 break;
799 805
800 heap [k] = heap [c]; 806 heap [k] = heap [c];
801 ((W)heap [k])->active = k + 1; 807 ev_active (heap [k]) = k;
802 808
803 k = c; 809 k = c;
804 } 810 }
805 811
806 heap [k] = w; 812 heap [k] = w;
807 ((W)heap [k])->active = k + 1; 813 ev_active (heap [k]) = k;
808} 814}
809 815
810void inline_size 816void inline_size
811adjustheap (WT *heap, int N, int k) 817adjustheap (WT *heap, int N, int k)
812{ 818{
908pipecb (EV_P_ ev_io *iow, int revents) 914pipecb (EV_P_ ev_io *iow, int revents)
909{ 915{
910#if EV_USE_EVENTFD 916#if EV_USE_EVENTFD
911 if (evfd >= 0) 917 if (evfd >= 0)
912 { 918 {
913 uint64_t counter = 1; 919 uint64_t counter;
914 read (evfd, &counter, sizeof (uint64_t)); 920 read (evfd, &counter, sizeof (uint64_t));
915 } 921 }
916 else 922 else
917#endif 923#endif
918 { 924 {
1364void 1370void
1365ev_loop_fork (EV_P) 1371ev_loop_fork (EV_P)
1366{ 1372{
1367 postfork = 1; /* must be in line with ev_default_fork */ 1373 postfork = 1; /* must be in line with ev_default_fork */
1368} 1374}
1369
1370#endif 1375#endif
1371 1376
1372#if EV_MULTIPLICITY 1377#if EV_MULTIPLICITY
1373struct ev_loop * 1378struct ev_loop *
1374ev_default_loop_init (unsigned int flags) 1379ev_default_loop_init (unsigned int flags)
1455 EV_CB_INVOKE (p->w, p->events); 1460 EV_CB_INVOKE (p->w, p->events);
1456 } 1461 }
1457 } 1462 }
1458} 1463}
1459 1464
1460void inline_size
1461timers_reify (EV_P)
1462{
1463 while (timercnt && ((WT)timers [0])->at <= mn_now)
1464 {
1465 ev_timer *w = (ev_timer *)timers [0];
1466
1467 /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/
1468
1469 /* first reschedule or stop timer */
1470 if (w->repeat)
1471 {
1472 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.));
1473
1474 ((WT)w)->at += w->repeat;
1475 if (((WT)w)->at < mn_now)
1476 ((WT)w)->at = mn_now;
1477
1478 downheap (timers, timercnt, 0);
1479 }
1480 else
1481 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
1482
1483 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT);
1484 }
1485}
1486
1487#if EV_PERIODIC_ENABLE
1488void inline_size
1489periodics_reify (EV_P)
1490{
1491 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now)
1492 {
1493 ev_periodic *w = (ev_periodic *)periodics [0];
1494
1495 /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/
1496
1497 /* first reschedule or stop timer */
1498 if (w->reschedule_cb)
1499 {
1500 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + TIME_EPSILON);
1501 assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now));
1502 downheap (periodics, periodiccnt, 0);
1503 }
1504 else if (w->interval)
1505 {
1506 ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1507 if (((WT)w)->at - ev_rt_now <= TIME_EPSILON) ((WT)w)->at += w->interval;
1508 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now));
1509 downheap (periodics, periodiccnt, 0);
1510 }
1511 else
1512 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
1513
1514 ev_feed_event (EV_A_ (W)w, EV_PERIODIC);
1515 }
1516}
1517
1518static void noinline
1519periodics_reschedule (EV_P)
1520{
1521 int i;
1522
1523 /* adjust periodics after time jump */
1524 for (i = 0; i < periodiccnt; ++i)
1525 {
1526 ev_periodic *w = (ev_periodic *)periodics [i];
1527
1528 if (w->reschedule_cb)
1529 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now);
1530 else if (w->interval)
1531 ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1532 }
1533
1534 /* now rebuild the heap */
1535 for (i = periodiccnt >> 1; i--; )
1536 downheap (periodics, periodiccnt, i);
1537}
1538#endif
1539
1540#if EV_IDLE_ENABLE 1465#if EV_IDLE_ENABLE
1541void inline_size 1466void inline_size
1542idle_reify (EV_P) 1467idle_reify (EV_P)
1543{ 1468{
1544 if (expect_false (idleall)) 1469 if (expect_false (idleall))
1555 queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE); 1480 queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE);
1556 break; 1481 break;
1557 } 1482 }
1558 } 1483 }
1559 } 1484 }
1485}
1486#endif
1487
1488void inline_size
1489timers_reify (EV_P)
1490{
1491 while (timercnt && ev_at (timers [1]) <= mn_now)
1492 {
1493 ev_timer *w = (ev_timer *)timers [1];
1494
1495 /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/
1496
1497 /* first reschedule or stop timer */
1498 if (w->repeat)
1499 {
1500 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.));
1501
1502 ev_at (w) += w->repeat;
1503 if (ev_at (w) < mn_now)
1504 ev_at (w) = mn_now;
1505
1506 downheap (timers, timercnt, 1);
1507 }
1508 else
1509 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
1510
1511 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT);
1512 }
1513}
1514
1515#if EV_PERIODIC_ENABLE
1516void inline_size
1517periodics_reify (EV_P)
1518{
1519 while (periodiccnt && ev_at (periodics [1]) <= ev_rt_now)
1520 {
1521 ev_periodic *w = (ev_periodic *)periodics [1];
1522
1523 /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/
1524
1525 /* first reschedule or stop timer */
1526 if (w->reschedule_cb)
1527 {
1528 ev_at (w) = w->reschedule_cb (w, ev_rt_now + TIME_EPSILON);
1529 assert (("ev_periodic reschedule callback returned time in the past", ev_at (w) > ev_rt_now));
1530 downheap (periodics, periodiccnt, 1);
1531 }
1532 else if (w->interval)
1533 {
1534 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1535 if (ev_at (w) - ev_rt_now <= TIME_EPSILON) ev_at (w) += w->interval;
1536 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ev_at (w) > ev_rt_now));
1537 downheap (periodics, periodiccnt, 1);
1538 }
1539 else
1540 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
1541
1542 ev_feed_event (EV_A_ (W)w, EV_PERIODIC);
1543 }
1544}
1545
1546static void noinline
1547periodics_reschedule (EV_P)
1548{
1549 int i;
1550
1551 /* adjust periodics after time jump */
1552 for (i = 1; i <= periodiccnt; ++i)
1553 {
1554 ev_periodic *w = (ev_periodic *)periodics [i];
1555
1556 if (w->reschedule_cb)
1557 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
1558 else if (w->interval)
1559 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1560 }
1561
1562 /* now rebuild the heap */
1563 for (i = periodiccnt >> 1; i--; )
1564 downheap (periodics, periodiccnt, i);
1560} 1565}
1561#endif 1566#endif
1562 1567
1563void inline_speed 1568void inline_speed
1564time_update (EV_P_ ev_tstamp max_block) 1569time_update (EV_P_ ev_tstamp max_block)
1593 */ 1598 */
1594 for (i = 4; --i; ) 1599 for (i = 4; --i; )
1595 { 1600 {
1596 rtmn_diff = ev_rt_now - mn_now; 1601 rtmn_diff = ev_rt_now - mn_now;
1597 1602
1598 if (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP) 1603 if (expect_true (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP))
1599 return; /* all is well */ 1604 return; /* all is well */
1600 1605
1601 ev_rt_now = ev_time (); 1606 ev_rt_now = ev_time ();
1602 mn_now = get_clock (); 1607 mn_now = get_clock ();
1603 now_floor = mn_now; 1608 now_floor = mn_now;
1618 { 1623 {
1619#if EV_PERIODIC_ENABLE 1624#if EV_PERIODIC_ENABLE
1620 periodics_reschedule (EV_A); 1625 periodics_reschedule (EV_A);
1621#endif 1626#endif
1622 /* adjust timers. this is easy, as the offset is the same for all of them */ 1627 /* adjust timers. this is easy, as the offset is the same for all of them */
1623 for (i = 0; i < timercnt; ++i) 1628 for (i = 1; i <= timercnt; ++i)
1624 ((WT)timers [i])->at += ev_rt_now - mn_now; 1629 ev_at (timers [i]) += ev_rt_now - mn_now;
1625 } 1630 }
1626 1631
1627 mn_now = ev_rt_now; 1632 mn_now = ev_rt_now;
1628 } 1633 }
1629} 1634}
1699 1704
1700 waittime = MAX_BLOCKTIME; 1705 waittime = MAX_BLOCKTIME;
1701 1706
1702 if (timercnt) 1707 if (timercnt)
1703 { 1708 {
1704 ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge; 1709 ev_tstamp to = ev_at (timers [1]) - mn_now + backend_fudge;
1705 if (waittime > to) waittime = to; 1710 if (waittime > to) waittime = to;
1706 } 1711 }
1707 1712
1708#if EV_PERIODIC_ENABLE 1713#if EV_PERIODIC_ENABLE
1709 if (periodiccnt) 1714 if (periodiccnt)
1710 { 1715 {
1711 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + backend_fudge; 1716 ev_tstamp to = ev_at (periodics [1]) - ev_rt_now + backend_fudge;
1712 if (waittime > to) waittime = to; 1717 if (waittime > to) waittime = to;
1713 } 1718 }
1714#endif 1719#endif
1715 1720
1716 if (expect_false (waittime < timeout_blocktime)) 1721 if (expect_false (waittime < timeout_blocktime))
1882ev_timer_start (EV_P_ ev_timer *w) 1887ev_timer_start (EV_P_ ev_timer *w)
1883{ 1888{
1884 if (expect_false (ev_is_active (w))) 1889 if (expect_false (ev_is_active (w)))
1885 return; 1890 return;
1886 1891
1887 ((WT)w)->at += mn_now; 1892 ev_at (w) += mn_now;
1888 1893
1889 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1894 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1890 1895
1891 ev_start (EV_A_ (W)w, ++timercnt); 1896 ev_start (EV_A_ (W)w, ++timercnt);
1892 array_needsize (WT, timers, timermax, timercnt, EMPTY2); 1897 array_needsize (WT, timers, timermax, timercnt + 1, EMPTY2);
1893 timers [timercnt - 1] = (WT)w; 1898 timers [timercnt] = (WT)w;
1894 upheap (timers, timercnt - 1); 1899 upheap (timers, timercnt);
1895 1900
1896 /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ 1901 /*assert (("internal timer heap corruption", timers [ev_active (w)] == w));*/
1897} 1902}
1898 1903
1899void noinline 1904void noinline
1900ev_timer_stop (EV_P_ ev_timer *w) 1905ev_timer_stop (EV_P_ ev_timer *w)
1901{ 1906{
1902 clear_pending (EV_A_ (W)w); 1907 clear_pending (EV_A_ (W)w);
1903 if (expect_false (!ev_is_active (w))) 1908 if (expect_false (!ev_is_active (w)))
1904 return; 1909 return;
1905 1910
1906 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == (WT)w));
1907
1908 { 1911 {
1909 int active = ((W)w)->active; 1912 int active = ev_active (w);
1910 1913
1914 assert (("internal timer heap corruption", timers [active] == (WT)w));
1915
1911 if (expect_true (--active < --timercnt)) 1916 if (expect_true (active < timercnt))
1912 { 1917 {
1913 timers [active] = timers [timercnt]; 1918 timers [active] = timers [timercnt];
1914 adjustheap (timers, timercnt, active); 1919 adjustheap (timers, timercnt, active);
1915 } 1920 }
1921
1922 --timercnt;
1916 } 1923 }
1917 1924
1918 ((WT)w)->at -= mn_now; 1925 ev_at (w) -= mn_now;
1919 1926
1920 ev_stop (EV_A_ (W)w); 1927 ev_stop (EV_A_ (W)w);
1921} 1928}
1922 1929
1923void noinline 1930void noinline
1925{ 1932{
1926 if (ev_is_active (w)) 1933 if (ev_is_active (w))
1927 { 1934 {
1928 if (w->repeat) 1935 if (w->repeat)
1929 { 1936 {
1930 ((WT)w)->at = mn_now + w->repeat; 1937 ev_at (w) = mn_now + w->repeat;
1931 adjustheap (timers, timercnt, ((W)w)->active - 1); 1938 adjustheap (timers, timercnt, ev_active (w));
1932 } 1939 }
1933 else 1940 else
1934 ev_timer_stop (EV_A_ w); 1941 ev_timer_stop (EV_A_ w);
1935 } 1942 }
1936 else if (w->repeat) 1943 else if (w->repeat)
1937 { 1944 {
1938 w->at = w->repeat; 1945 ev_at (w) = w->repeat;
1939 ev_timer_start (EV_A_ w); 1946 ev_timer_start (EV_A_ w);
1940 } 1947 }
1941} 1948}
1942 1949
1943#if EV_PERIODIC_ENABLE 1950#if EV_PERIODIC_ENABLE
1946{ 1953{
1947 if (expect_false (ev_is_active (w))) 1954 if (expect_false (ev_is_active (w)))
1948 return; 1955 return;
1949 1956
1950 if (w->reschedule_cb) 1957 if (w->reschedule_cb)
1951 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); 1958 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
1952 else if (w->interval) 1959 else if (w->interval)
1953 { 1960 {
1954 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); 1961 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.));
1955 /* this formula differs from the one in periodic_reify because we do not always round up */ 1962 /* this formula differs from the one in periodic_reify because we do not always round up */
1956 ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 1963 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1957 } 1964 }
1958 else 1965 else
1959 ((WT)w)->at = w->offset; 1966 ev_at (w) = w->offset;
1960 1967
1961 ev_start (EV_A_ (W)w, ++periodiccnt); 1968 ev_start (EV_A_ (W)w, ++periodiccnt);
1962 array_needsize (WT, periodics, periodicmax, periodiccnt, EMPTY2); 1969 array_needsize (WT, periodics, periodicmax, periodiccnt + 1, EMPTY2);
1963 periodics [periodiccnt - 1] = (WT)w; 1970 periodics [periodiccnt] = (WT)w;
1964 upheap (periodics, periodiccnt - 1); 1971 upheap (periodics, periodiccnt);
1965 1972
1966 /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ 1973 /*assert (("internal periodic heap corruption", periodics [ev_active (w)] == w));*/
1967} 1974}
1968 1975
1969void noinline 1976void noinline
1970ev_periodic_stop (EV_P_ ev_periodic *w) 1977ev_periodic_stop (EV_P_ ev_periodic *w)
1971{ 1978{
1972 clear_pending (EV_A_ (W)w); 1979 clear_pending (EV_A_ (W)w);
1973 if (expect_false (!ev_is_active (w))) 1980 if (expect_false (!ev_is_active (w)))
1974 return; 1981 return;
1975 1982
1976 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == (WT)w));
1977
1978 { 1983 {
1979 int active = ((W)w)->active; 1984 int active = ev_active (w);
1980 1985
1986 assert (("internal periodic heap corruption", periodics [active] == (WT)w));
1987
1981 if (expect_true (--active < --periodiccnt)) 1988 if (expect_true (active < periodiccnt))
1982 { 1989 {
1983 periodics [active] = periodics [periodiccnt]; 1990 periodics [active] = periodics [periodiccnt];
1984 adjustheap (periodics, periodiccnt, active); 1991 adjustheap (periodics, periodiccnt, active);
1985 } 1992 }
1993
1994 --periodiccnt;
1986 } 1995 }
1987 1996
1988 ev_stop (EV_A_ (W)w); 1997 ev_stop (EV_A_ (W)w);
1989} 1998}
1990 1999
2106 if (w->wd < 0) 2115 if (w->wd < 0)
2107 { 2116 {
2108 ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */ 2117 ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */
2109 2118
2110 /* monitor some parent directory for speedup hints */ 2119 /* monitor some parent directory for speedup hints */
2120 /* note that exceeding the hardcoded limit is not a correctness issue, */
2121 /* but an efficiency issue only */
2111 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) 2122 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096)
2112 { 2123 {
2113 char path [4096]; 2124 char path [4096];
2114 strcpy (path, w->path); 2125 strcpy (path, w->path);
2115 2126
2360 clear_pending (EV_A_ (W)w); 2371 clear_pending (EV_A_ (W)w);
2361 if (expect_false (!ev_is_active (w))) 2372 if (expect_false (!ev_is_active (w)))
2362 return; 2373 return;
2363 2374
2364 { 2375 {
2365 int active = ((W)w)->active; 2376 int active = ev_active (w);
2366 2377
2367 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; 2378 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]];
2368 ((W)idles [ABSPRI (w)][active - 1])->active = active; 2379 ev_active (idles [ABSPRI (w)][active - 1]) = active;
2369 2380
2370 ev_stop (EV_A_ (W)w); 2381 ev_stop (EV_A_ (W)w);
2371 --idleall; 2382 --idleall;
2372 } 2383 }
2373} 2384}
2390 clear_pending (EV_A_ (W)w); 2401 clear_pending (EV_A_ (W)w);
2391 if (expect_false (!ev_is_active (w))) 2402 if (expect_false (!ev_is_active (w)))
2392 return; 2403 return;
2393 2404
2394 { 2405 {
2395 int active = ((W)w)->active; 2406 int active = ev_active (w);
2407
2396 prepares [active - 1] = prepares [--preparecnt]; 2408 prepares [active - 1] = prepares [--preparecnt];
2397 ((W)prepares [active - 1])->active = active; 2409 ev_active (prepares [active - 1]) = active;
2398 } 2410 }
2399 2411
2400 ev_stop (EV_A_ (W)w); 2412 ev_stop (EV_A_ (W)w);
2401} 2413}
2402 2414
2417 clear_pending (EV_A_ (W)w); 2429 clear_pending (EV_A_ (W)w);
2418 if (expect_false (!ev_is_active (w))) 2430 if (expect_false (!ev_is_active (w)))
2419 return; 2431 return;
2420 2432
2421 { 2433 {
2422 int active = ((W)w)->active; 2434 int active = ev_active (w);
2435
2423 checks [active - 1] = checks [--checkcnt]; 2436 checks [active - 1] = checks [--checkcnt];
2424 ((W)checks [active - 1])->active = active; 2437 ev_active (checks [active - 1]) = active;
2425 } 2438 }
2426 2439
2427 ev_stop (EV_A_ (W)w); 2440 ev_stop (EV_A_ (W)w);
2428} 2441}
2429 2442
2525 clear_pending (EV_A_ (W)w); 2538 clear_pending (EV_A_ (W)w);
2526 if (expect_false (!ev_is_active (w))) 2539 if (expect_false (!ev_is_active (w)))
2527 return; 2540 return;
2528 2541
2529 { 2542 {
2530 int active = ((W)w)->active; 2543 int active = ev_active (w);
2544
2531 forks [active - 1] = forks [--forkcnt]; 2545 forks [active - 1] = forks [--forkcnt];
2532 ((W)forks [active - 1])->active = active; 2546 ev_active (forks [active - 1]) = active;
2533 } 2547 }
2534 2548
2535 ev_stop (EV_A_ (W)w); 2549 ev_stop (EV_A_ (W)w);
2536} 2550}
2537#endif 2551#endif
2556 clear_pending (EV_A_ (W)w); 2570 clear_pending (EV_A_ (W)w);
2557 if (expect_false (!ev_is_active (w))) 2571 if (expect_false (!ev_is_active (w)))
2558 return; 2572 return;
2559 2573
2560 { 2574 {
2561 int active = ((W)w)->active; 2575 int active = ev_active (w);
2576
2562 asyncs [active - 1] = asyncs [--asynccnt]; 2577 asyncs [active - 1] = asyncs [--asynccnt];
2563 ((W)asyncs [active - 1])->active = active; 2578 ev_active (asyncs [active - 1]) = active;
2564 } 2579 }
2565 2580
2566 ev_stop (EV_A_ (W)w); 2581 ev_stop (EV_A_ (W)w);
2567} 2582}
2568 2583

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines