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

Comparing libev/ev.c (file contents):
Revision 1.229 by root, Fri May 2 08:08:45 2008 UTC vs.
Revision 1.236 by root, Wed May 7 14:46:22 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines