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

Comparing libev/ev.c (file contents):
Revision 1.228 by root, Fri May 2 08:07:37 2008 UTC vs.
Revision 1.235 by root, Wed May 7 14:45:17 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
330#define ev_at(w) ((WT)(w))->at 331#define ev_at(w) ((WT)(w))->at
331 332
332#if EV_USE_MONOTONIC 333#if EV_USE_MONOTONIC
333/* 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 */
334/* giving it a reasonably high chance of working on typical architetcures */ 335/* giving it a reasonably high chance of working on typical architetcures */
519 } 520 }
520} 521}
521 522
522/*****************************************************************************/ 523/*****************************************************************************/
523 524
525#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */
526
524int inline_size 527int inline_size
525array_nextsize (int elem, int cur, int cnt) 528array_nextsize (int elem, int cur, int cnt)
526{ 529{
527 int ncur = cur + 1; 530 int ncur = cur + 1;
528 531
529 do 532 do
530 ncur <<= 1; 533 ncur <<= 1;
531 while (cnt > ncur); 534 while (cnt > ncur);
532 535
533 /* 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 */
534 if (elem * ncur > 4096) 537 if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4)
535 { 538 {
536 ncur *= elem; 539 ncur *= elem;
537 ncur = (ncur + elem + 4095 + sizeof (void *) * 4) & ~4095; 540 ncur = (ncur + elem + (MALLOC_ROUND - 1) + sizeof (void *) * 4) & ~(MALLOC_ROUND - 1);
538 ncur = ncur - sizeof (void *) * 4; 541 ncur = ncur - sizeof (void *) * 4;
539 ncur /= elem; 542 ncur /= elem;
540 } 543 }
541 544
542 return ncur; 545 return ncur;
756 } 759 }
757} 760}
758 761
759/*****************************************************************************/ 762/*****************************************************************************/
760 763
764/*
765 * at the moment we allow libev the luxury of two heaps,
766 * a small-code-size 2-heap one and a ~1.5kb larger 4-heap
767 * which is more cache-efficient.
768 * the difference is about 5% with 50000+ watchers.
769 */
770#define USE_4HEAP !EV_MINIMAL
771#if USE_4HEAP
772
773#define HEAP0 3 /* index of first element in heap */
774
761/* towards the root */ 775/* towards the root */
762void inline_speed 776void inline_speed
763upheap (WT *heap, int k) 777upheap (WT *heap, int k)
764{ 778{
765 WT w = heap [k]; 779 WT w = heap [k];
766 780
767 for (;;) 781 for (;;)
768 { 782 {
783 int p = ((k - HEAP0 - 1) / 4) + HEAP0;
784
785 if (p >= HEAP0 || heap [p]->at <= w->at)
786 break;
787
788 heap [k] = heap [p];
789 ev_active (heap [k]) = k;
790 k = p;
791 }
792
793 heap [k] = w;
794 ev_active (heap [k]) = k;
795}
796
797/* away from the root */
798void inline_speed
799downheap (WT *heap, int N, int k)
800{
801 WT w = heap [k];
802 WT *E = heap + N + HEAP0;
803
804 for (;;)
805 {
806 ev_tstamp minat;
807 WT *minpos;
808 WT *pos = heap + 4 * (k - HEAP0) + HEAP0;
809
810 // find minimum child
811 if (expect_true (pos +3 < E))
812 {
813 (minpos = pos + 0), (minat = (*minpos)->at);
814 if (pos [1]->at < minat) (minpos = pos + 1), (minat = (*minpos)->at);
815 if (pos [2]->at < minat) (minpos = pos + 2), (minat = (*minpos)->at);
816 if (pos [3]->at < minat) (minpos = pos + 3), (minat = (*minpos)->at);
817 }
818 else
819 {
820 if (pos >= E)
821 break;
822
823 (minpos = pos + 0), (minat = (*minpos)->at);
824 if (pos + 1 < E && pos [1]->at < minat) (minpos = pos + 1), (minat = (*minpos)->at);
825 if (pos + 2 < E && pos [2]->at < minat) (minpos = pos + 2), (minat = (*minpos)->at);
826 if (pos + 3 < E && pos [3]->at < minat) (minpos = pos + 3), (minat = (*minpos)->at);
827 }
828
829 if (w->at <= minat)
830 break;
831
832 ev_active (*minpos) = k;
833 heap [k] = *minpos;
834
835 k = minpos - heap;
836 }
837
838 heap [k] = w;
839 ev_active (heap [k]) = k;
840}
841
842#else // 4HEAP
843
844#define HEAP0 1
845
846/* towards the root */
847void inline_speed
848upheap (WT *heap, int k)
849{
850 WT w = heap [k];
851
852 for (;;)
853 {
769 int p = k >> 1; 854 int p = k >> 1;
770 855
771 /* maybe we could use a dummy element at heap [0]? */ 856 /* maybe we could use a dummy element at heap [0]? */
772 if (!p || heap [p]->at <= w->at) 857 if (!p || heap [p]->at <= w->at)
773 break; 858 break;
774 859
775 heap [k] = heap [p]; 860 heap [k] = heap [p];
776 ((W)heap [k])->active = k; 861 ev_active (heap [k]) = k;
777 k = p; 862 k = p;
778 } 863 }
779 864
780 heap [k] = w; 865 heap [k] = w;
781 ((W)heap [k])->active = k; 866 ev_active (heap [k]) = k;
782} 867}
783 868
784/* away from the root */ 869/* away from the root */
785void inline_speed 870void inline_speed
786downheap (WT *heap, int N, int k) 871downheap (WT *heap, int N, int k)
792 int c = k << 1; 877 int c = k << 1;
793 878
794 if (c > N) 879 if (c > N)
795 break; 880 break;
796 881
797 c += c < N && heap [c]->at > heap [c + 1]->at 882 c += c + 1 < N && heap [c]->at > heap [c + 1]->at
798 ? 1 : 0; 883 ? 1 : 0;
799 884
800 if (w->at <= heap [c]->at) 885 if (w->at <= heap [c]->at)
801 break; 886 break;
802 887
803 heap [k] = heap [c]; 888 heap [k] = heap [c];
804 ((W)heap [k])->active = k; 889 ((W)heap [k])->active = k;
805 890
806 k = c; 891 k = c;
807 } 892 }
808 893
809 heap [k] = w; 894 heap [k] = w;
810 ((W)heap [k])->active = k; 895 ev_active (heap [k]) = k;
811} 896}
897#endif
812 898
813void inline_size 899void inline_size
814adjustheap (WT *heap, int N, int k) 900adjustheap (WT *heap, int N, int k)
815{ 901{
816 upheap (heap, k); 902 upheap (heap, k);
911pipecb (EV_P_ ev_io *iow, int revents) 997pipecb (EV_P_ ev_io *iow, int revents)
912{ 998{
913#if EV_USE_EVENTFD 999#if EV_USE_EVENTFD
914 if (evfd >= 0) 1000 if (evfd >= 0)
915 { 1001 {
916 uint64_t counter = 1; 1002 uint64_t counter;
917 read (evfd, &counter, sizeof (uint64_t)); 1003 read (evfd, &counter, sizeof (uint64_t));
918 } 1004 }
919 else 1005 else
920#endif 1006#endif
921 { 1007 {
1367void 1453void
1368ev_loop_fork (EV_P) 1454ev_loop_fork (EV_P)
1369{ 1455{
1370 postfork = 1; /* must be in line with ev_default_fork */ 1456 postfork = 1; /* must be in line with ev_default_fork */
1371} 1457}
1372
1373#endif 1458#endif
1374 1459
1375#if EV_MULTIPLICITY 1460#if EV_MULTIPLICITY
1376struct ev_loop * 1461struct ev_loop *
1377ev_default_loop_init (unsigned int flags) 1462ev_default_loop_init (unsigned int flags)
1458 EV_CB_INVOKE (p->w, p->events); 1543 EV_CB_INVOKE (p->w, p->events);
1459 } 1544 }
1460 } 1545 }
1461} 1546}
1462 1547
1548#if EV_IDLE_ENABLE
1549void inline_size
1550idle_reify (EV_P)
1551{
1552 if (expect_false (idleall))
1553 {
1554 int pri;
1555
1556 for (pri = NUMPRI; pri--; )
1557 {
1558 if (pendingcnt [pri])
1559 break;
1560
1561 if (idlecnt [pri])
1562 {
1563 queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE);
1564 break;
1565 }
1566 }
1567 }
1568}
1569#endif
1570
1463void inline_size 1571void inline_size
1464timers_reify (EV_P) 1572timers_reify (EV_P)
1465{ 1573{
1466 while (timercnt && ev_at (timers [1]) <= mn_now) 1574 while (timercnt && ev_at (timers [HEAP0]) <= mn_now)
1467 { 1575 {
1468 ev_timer *w = (ev_timer *)timers [1]; 1576 ev_timer *w = (ev_timer *)timers [HEAP0];
1469 1577
1470 /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ 1578 /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/
1471 1579
1472 /* first reschedule or stop timer */ 1580 /* first reschedule or stop timer */
1473 if (w->repeat) 1581 if (w->repeat)
1476 1584
1477 ev_at (w) += w->repeat; 1585 ev_at (w) += w->repeat;
1478 if (ev_at (w) < mn_now) 1586 if (ev_at (w) < mn_now)
1479 ev_at (w) = mn_now; 1587 ev_at (w) = mn_now;
1480 1588
1481 downheap (timers, timercnt, 1); 1589 downheap (timers, timercnt, HEAP0);
1482 } 1590 }
1483 else 1591 else
1484 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ 1592 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
1485 1593
1486 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); 1594 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT);
1489 1597
1490#if EV_PERIODIC_ENABLE 1598#if EV_PERIODIC_ENABLE
1491void inline_size 1599void inline_size
1492periodics_reify (EV_P) 1600periodics_reify (EV_P)
1493{ 1601{
1494 while (periodiccnt && ev_at (periodics [1]) <= ev_rt_now) 1602 while (periodiccnt && ev_at (periodics [HEAP0]) <= ev_rt_now)
1495 { 1603 {
1496 ev_periodic *w = (ev_periodic *)periodics [1]; 1604 ev_periodic *w = (ev_periodic *)periodics [HEAP0];
1497 1605
1498 /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ 1606 /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/
1499 1607
1500 /* first reschedule or stop timer */ 1608 /* first reschedule or stop timer */
1501 if (w->reschedule_cb) 1609 if (w->reschedule_cb)
1507 else if (w->interval) 1615 else if (w->interval)
1508 { 1616 {
1509 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 1617 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1510 if (ev_at (w) - ev_rt_now <= TIME_EPSILON) ev_at (w) += w->interval; 1618 if (ev_at (w) - ev_rt_now <= TIME_EPSILON) ev_at (w) += w->interval;
1511 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ev_at (w) > ev_rt_now)); 1619 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ev_at (w) > ev_rt_now));
1512 downheap (periodics, periodiccnt, 1); 1620 downheap (periodics, periodiccnt, HEAP0);
1513 } 1621 }
1514 else 1622 else
1515 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ 1623 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
1516 1624
1517 ev_feed_event (EV_A_ (W)w, EV_PERIODIC); 1625 ev_feed_event (EV_A_ (W)w, EV_PERIODIC);
1522periodics_reschedule (EV_P) 1630periodics_reschedule (EV_P)
1523{ 1631{
1524 int i; 1632 int i;
1525 1633
1526 /* adjust periodics after time jump */ 1634 /* adjust periodics after time jump */
1527 for (i = 0; i < periodiccnt; ++i) 1635 for (i = 1; i <= periodiccnt; ++i)
1528 { 1636 {
1529 ev_periodic *w = (ev_periodic *)periodics [i]; 1637 ev_periodic *w = (ev_periodic *)periodics [i];
1530 1638
1531 if (w->reschedule_cb) 1639 if (w->reschedule_cb)
1532 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 1640 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
1533 else if (w->interval) 1641 else if (w->interval)
1534 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 1642 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1535 } 1643 }
1536 1644
1537 /* now rebuild the heap */ 1645 /* now rebuild the heap */
1538 for (i = periodiccnt >> 1; i--; ) 1646 for (i = periodiccnt >> 1; --i; )
1539 downheap (periodics, periodiccnt, i); 1647 downheap (periodics, periodiccnt, i + HEAP0);
1540}
1541#endif
1542
1543#if EV_IDLE_ENABLE
1544void inline_size
1545idle_reify (EV_P)
1546{
1547 if (expect_false (idleall))
1548 {
1549 int pri;
1550
1551 for (pri = NUMPRI; pri--; )
1552 {
1553 if (pendingcnt [pri])
1554 break;
1555
1556 if (idlecnt [pri])
1557 {
1558 queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE);
1559 break;
1560 }
1561 }
1562 }
1563} 1648}
1564#endif 1649#endif
1565 1650
1566void inline_speed 1651void inline_speed
1567time_update (EV_P_ ev_tstamp max_block) 1652time_update (EV_P_ ev_tstamp max_block)
1596 */ 1681 */
1597 for (i = 4; --i; ) 1682 for (i = 4; --i; )
1598 { 1683 {
1599 rtmn_diff = ev_rt_now - mn_now; 1684 rtmn_diff = ev_rt_now - mn_now;
1600 1685
1601 if (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP) 1686 if (expect_true (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP))
1602 return; /* all is well */ 1687 return; /* all is well */
1603 1688
1604 ev_rt_now = ev_time (); 1689 ev_rt_now = ev_time ();
1605 mn_now = get_clock (); 1690 mn_now = get_clock ();
1606 now_floor = mn_now; 1691 now_floor = mn_now;
1702 1787
1703 waittime = MAX_BLOCKTIME; 1788 waittime = MAX_BLOCKTIME;
1704 1789
1705 if (timercnt) 1790 if (timercnt)
1706 { 1791 {
1707 ev_tstamp to = ev_at (timers [1]) - mn_now + backend_fudge; 1792 ev_tstamp to = ev_at (timers [HEAP0]) - mn_now + backend_fudge;
1708 if (waittime > to) waittime = to; 1793 if (waittime > to) waittime = to;
1709 } 1794 }
1710 1795
1711#if EV_PERIODIC_ENABLE 1796#if EV_PERIODIC_ENABLE
1712 if (periodiccnt) 1797 if (periodiccnt)
1713 { 1798 {
1714 ev_tstamp to = ev_at (periodics [1]) - ev_rt_now + backend_fudge; 1799 ev_tstamp to = ev_at (periodics [HEAP0]) - ev_rt_now + backend_fudge;
1715 if (waittime > to) waittime = to; 1800 if (waittime > to) waittime = to;
1716 } 1801 }
1717#endif 1802#endif
1718 1803
1719 if (expect_false (waittime < timeout_blocktime)) 1804 if (expect_false (waittime < timeout_blocktime))
1889 1974
1890 ev_at (w) += mn_now; 1975 ev_at (w) += mn_now;
1891 1976
1892 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1977 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1893 1978
1894 ev_start (EV_A_ (W)w, ++timercnt); 1979 ev_start (EV_A_ (W)w, ++timercnt + HEAP0 - 1);
1895 array_needsize (WT, timers, timermax, timercnt + 1, EMPTY2); 1980 array_needsize (WT, timers, timermax, timercnt + HEAP0, EMPTY2);
1896 timers [timercnt] = (WT)w; 1981 timers [ev_active (w)] = (WT)w;
1897 upheap (timers, timercnt); 1982 upheap (timers, ev_active (w));
1898 1983
1899 /*assert (("internal timer heap corruption", timers [((W)w)->active] == w));*/ 1984 /*assert (("internal timer heap corruption", timers [ev_active (w)] == w));*/
1900} 1985}
1901 1986
1902void noinline 1987void noinline
1903ev_timer_stop (EV_P_ ev_timer *w) 1988ev_timer_stop (EV_P_ ev_timer *w)
1904{ 1989{
1905 clear_pending (EV_A_ (W)w); 1990 clear_pending (EV_A_ (W)w);
1906 if (expect_false (!ev_is_active (w))) 1991 if (expect_false (!ev_is_active (w)))
1907 return; 1992 return;
1908 1993
1909 assert (("internal timer heap corruption", timers [((W)w)->active] == (WT)w));
1910
1911 { 1994 {
1912 int active = ((W)w)->active; 1995 int active = ev_active (w);
1913 1996
1997 assert (("internal timer heap corruption", timers [active] == (WT)w));
1998
1914 if (expect_true (active < timercnt)) 1999 if (expect_true (active < timercnt + HEAP0 - 1))
1915 { 2000 {
1916 timers [active] = timers [timercnt]; 2001 timers [active] = timers [timercnt + HEAP0 - 1];
1917 adjustheap (timers, timercnt, active); 2002 adjustheap (timers, timercnt, active);
1918 } 2003 }
1919 2004
1920 --timercnt; 2005 --timercnt;
1921 } 2006 }
1931 if (ev_is_active (w)) 2016 if (ev_is_active (w))
1932 { 2017 {
1933 if (w->repeat) 2018 if (w->repeat)
1934 { 2019 {
1935 ev_at (w) = mn_now + w->repeat; 2020 ev_at (w) = mn_now + w->repeat;
1936 adjustheap (timers, timercnt, ((W)w)->active); 2021 adjustheap (timers, timercnt, ev_active (w));
1937 } 2022 }
1938 else 2023 else
1939 ev_timer_stop (EV_A_ w); 2024 ev_timer_stop (EV_A_ w);
1940 } 2025 }
1941 else if (w->repeat) 2026 else if (w->repeat)
1942 { 2027 {
1943 w->at = w->repeat; 2028 ev_at (w) = w->repeat;
1944 ev_timer_start (EV_A_ w); 2029 ev_timer_start (EV_A_ w);
1945 } 2030 }
1946} 2031}
1947 2032
1948#if EV_PERIODIC_ENABLE 2033#if EV_PERIODIC_ENABLE
1961 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 2046 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1962 } 2047 }
1963 else 2048 else
1964 ev_at (w) = w->offset; 2049 ev_at (w) = w->offset;
1965 2050
1966 ev_start (EV_A_ (W)w, ++periodiccnt); 2051 ev_start (EV_A_ (W)w, ++periodiccnt + HEAP0 - 1);
1967 array_needsize (WT, periodics, periodicmax, periodiccnt + 1, EMPTY2); 2052 array_needsize (WT, periodics, periodicmax, periodiccnt + HEAP0, EMPTY2);
1968 periodics [periodiccnt] = (WT)w; 2053 periodics [ev_active (w)] = (WT)w;
1969 upheap (periodics, periodiccnt); 2054 upheap (periodics, ev_active (w));
1970 2055
1971 /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ 2056 /*assert (("internal periodic heap corruption", periodics [ev_active (w)] == w));*/
1972} 2057}
1973 2058
1974void noinline 2059void noinline
1975ev_periodic_stop (EV_P_ ev_periodic *w) 2060ev_periodic_stop (EV_P_ ev_periodic *w)
1976{ 2061{
1977 clear_pending (EV_A_ (W)w); 2062 clear_pending (EV_A_ (W)w);
1978 if (expect_false (!ev_is_active (w))) 2063 if (expect_false (!ev_is_active (w)))
1979 return; 2064 return;
1980 2065
1981 assert (("internal periodic heap corruption", periodics [((W)w)->active] == (WT)w));
1982
1983 { 2066 {
1984 int active = ((W)w)->active; 2067 int active = ev_active (w);
1985 2068
2069 assert (("internal periodic heap corruption", periodics [active] == (WT)w));
2070
1986 if (expect_true (active < periodiccnt)) 2071 if (expect_true (active < periodiccnt + HEAP0 - 1))
1987 { 2072 {
1988 periodics [active] = periodics [periodiccnt]; 2073 periodics [active] = periodics [periodiccnt + HEAP0 - 1];
1989 adjustheap (periodics, periodiccnt, active); 2074 adjustheap (periodics, periodiccnt, active);
1990 } 2075 }
1991 2076
1992 --periodiccnt; 2077 --periodiccnt;
1993 } 2078 }
2113 if (w->wd < 0) 2198 if (w->wd < 0)
2114 { 2199 {
2115 ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */ 2200 ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */
2116 2201
2117 /* monitor some parent directory for speedup hints */ 2202 /* monitor some parent directory for speedup hints */
2203 /* note that exceeding the hardcoded limit is not a correctness issue, */
2204 /* but an efficiency issue only */
2118 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) 2205 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096)
2119 { 2206 {
2120 char path [4096]; 2207 char path [4096];
2121 strcpy (path, w->path); 2208 strcpy (path, w->path);
2122 2209
2367 clear_pending (EV_A_ (W)w); 2454 clear_pending (EV_A_ (W)w);
2368 if (expect_false (!ev_is_active (w))) 2455 if (expect_false (!ev_is_active (w)))
2369 return; 2456 return;
2370 2457
2371 { 2458 {
2372 int active = ((W)w)->active; 2459 int active = ev_active (w);
2373 2460
2374 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; 2461 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]];
2375 ((W)idles [ABSPRI (w)][active - 1])->active = active; 2462 ev_active (idles [ABSPRI (w)][active - 1]) = active;
2376 2463
2377 ev_stop (EV_A_ (W)w); 2464 ev_stop (EV_A_ (W)w);
2378 --idleall; 2465 --idleall;
2379 } 2466 }
2380} 2467}
2397 clear_pending (EV_A_ (W)w); 2484 clear_pending (EV_A_ (W)w);
2398 if (expect_false (!ev_is_active (w))) 2485 if (expect_false (!ev_is_active (w)))
2399 return; 2486 return;
2400 2487
2401 { 2488 {
2402 int active = ((W)w)->active; 2489 int active = ev_active (w);
2490
2403 prepares [active - 1] = prepares [--preparecnt]; 2491 prepares [active - 1] = prepares [--preparecnt];
2404 ((W)prepares [active - 1])->active = active; 2492 ev_active (prepares [active - 1]) = active;
2405 } 2493 }
2406 2494
2407 ev_stop (EV_A_ (W)w); 2495 ev_stop (EV_A_ (W)w);
2408} 2496}
2409 2497
2424 clear_pending (EV_A_ (W)w); 2512 clear_pending (EV_A_ (W)w);
2425 if (expect_false (!ev_is_active (w))) 2513 if (expect_false (!ev_is_active (w)))
2426 return; 2514 return;
2427 2515
2428 { 2516 {
2429 int active = ((W)w)->active; 2517 int active = ev_active (w);
2518
2430 checks [active - 1] = checks [--checkcnt]; 2519 checks [active - 1] = checks [--checkcnt];
2431 ((W)checks [active - 1])->active = active; 2520 ev_active (checks [active - 1]) = active;
2432 } 2521 }
2433 2522
2434 ev_stop (EV_A_ (W)w); 2523 ev_stop (EV_A_ (W)w);
2435} 2524}
2436 2525
2532 clear_pending (EV_A_ (W)w); 2621 clear_pending (EV_A_ (W)w);
2533 if (expect_false (!ev_is_active (w))) 2622 if (expect_false (!ev_is_active (w)))
2534 return; 2623 return;
2535 2624
2536 { 2625 {
2537 int active = ((W)w)->active; 2626 int active = ev_active (w);
2627
2538 forks [active - 1] = forks [--forkcnt]; 2628 forks [active - 1] = forks [--forkcnt];
2539 ((W)forks [active - 1])->active = active; 2629 ev_active (forks [active - 1]) = active;
2540 } 2630 }
2541 2631
2542 ev_stop (EV_A_ (W)w); 2632 ev_stop (EV_A_ (W)w);
2543} 2633}
2544#endif 2634#endif
2563 clear_pending (EV_A_ (W)w); 2653 clear_pending (EV_A_ (W)w);
2564 if (expect_false (!ev_is_active (w))) 2654 if (expect_false (!ev_is_active (w)))
2565 return; 2655 return;
2566 2656
2567 { 2657 {
2568 int active = ((W)w)->active; 2658 int active = ev_active (w);
2659
2569 asyncs [active - 1] = asyncs [--asynccnt]; 2660 asyncs [active - 1] = asyncs [--asynccnt];
2570 ((W)asyncs [active - 1])->active = active; 2661 ev_active (asyncs [active - 1]) = active;
2571 } 2662 }
2572 2663
2573 ev_stop (EV_A_ (W)w); 2664 ev_stop (EV_A_ (W)w);
2574} 2665}
2575 2666

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines