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.240 by root, Thu May 8 21:21:41 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 DHEAP 4
774#define HEAP0 (DHEAP - 1) /* index of first element in heap */
775
761/* towards the root */ 776/* towards the root */
762void inline_speed 777void inline_speed
763upheap (WT *heap, int k) 778upheap (WT *heap, int k)
764{ 779{
765 WT w = heap [k]; 780 WT w = heap [k];
781 ev_tstamp w_at = w->at;
782
783 for (;;)
784 {
785 int p = ((k - HEAP0 - 1) / DHEAP) + HEAP0;
786
787 if (p == k || heap [p]->at <= w_at)
788 break;
789
790 heap [k] = heap [p];
791 ev_active (heap [k]) = k;
792 k = p;
793 }
794
795 heap [k] = w;
796 ev_active (heap [k]) = k;
797}
798
799/* away from the root */
800void inline_speed
801downheap (WT *heap, int N, int k)
802{
803 WT w = heap [k];
804 WT *E = heap + N + HEAP0;
805
806 for (;;)
807 {
808 ev_tstamp minat;
809 WT *minpos;
810 WT *pos = heap + DHEAP * (k - HEAP0) + HEAP0;
811
812 // find minimum child
813 if (expect_true (pos + DHEAP - 1 < E))
814 {
815 /* fast path */ (minpos = pos + 0), (minat = (*minpos)->at);
816 if (pos [1]->at < minat) (minpos = pos + 1), (minat = (*minpos)->at);
817 if (pos [2]->at < minat) (minpos = pos + 2), (minat = (*minpos)->at);
818 if (pos [3]->at < minat) (minpos = pos + 3), (minat = (*minpos)->at);
819 }
820 else if (pos < E)
821 {
822 /* slow path */ (minpos = pos + 0), (minat = (*minpos)->at);
823 if (pos + 1 < E && pos [1]->at < minat) (minpos = pos + 1), (minat = (*minpos)->at);
824 if (pos + 2 < E && pos [2]->at < minat) (minpos = pos + 2), (minat = (*minpos)->at);
825 if (pos + 3 < E && pos [3]->at < minat) (minpos = pos + 3), (minat = (*minpos)->at);
826 }
827 else
828 break;
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];
766 852
767 for (;;) 853 for (;;)
768 { 854 {
769 int p = k >> 1; 855 int p = k >> 1;
770 856
771 /* maybe we could use a dummy element at heap [0]? */ 857 /* maybe we could use a dummy element at heap [0]? */
772 if (!p || heap [p]->at <= w->at) 858 if (!p || heap [p]->at <= w->at)
773 break; 859 break;
774 860
775 heap [k] = heap [p]; 861 heap [k] = heap [p];
776 ((W)heap [k])->active = k; 862 ev_active (heap [k]) = k;
777 k = p; 863 k = p;
778 } 864 }
779 865
780 heap [k] = w; 866 heap [k] = w;
781 ((W)heap [k])->active = k; 867 ev_active (heap [k]) = k;
782} 868}
783 869
784/* away from the root */ 870/* away from the root */
785void inline_speed 871void inline_speed
786downheap (WT *heap, int N, int k) 872downheap (WT *heap, int N, int k)
792 int c = k << 1; 878 int c = k << 1;
793 879
794 if (c > N) 880 if (c > N)
795 break; 881 break;
796 882
797 c += c < N && heap [c]->at > heap [c + 1]->at 883 c += c + 1 < N && heap [c]->at > heap [c + 1]->at
798 ? 1 : 0; 884 ? 1 : 0;
799 885
800 if (w->at <= heap [c]->at) 886 if (w->at <= heap [c]->at)
801 break; 887 break;
802 888
803 heap [k] = heap [c]; 889 heap [k] = heap [c];
804 ((W)heap [k])->active = k; 890 ((W)heap [k])->active = k;
805 891
806 k = c; 892 k = c;
807 } 893 }
808 894
809 heap [k] = w; 895 heap [k] = w;
810 ((W)heap [k])->active = k; 896 ev_active (heap [k]) = k;
811} 897}
898#endif
812 899
813void inline_size 900void inline_size
814adjustheap (WT *heap, int N, int k) 901adjustheap (WT *heap, int N, int k)
815{ 902{
816 upheap (heap, k); 903 upheap (heap, k);
911pipecb (EV_P_ ev_io *iow, int revents) 998pipecb (EV_P_ ev_io *iow, int revents)
912{ 999{
913#if EV_USE_EVENTFD 1000#if EV_USE_EVENTFD
914 if (evfd >= 0) 1001 if (evfd >= 0)
915 { 1002 {
916 uint64_t counter = 1; 1003 uint64_t counter;
917 read (evfd, &counter, sizeof (uint64_t)); 1004 read (evfd, &counter, sizeof (uint64_t));
918 } 1005 }
919 else 1006 else
920#endif 1007#endif
921 { 1008 {
1367void 1454void
1368ev_loop_fork (EV_P) 1455ev_loop_fork (EV_P)
1369{ 1456{
1370 postfork = 1; /* must be in line with ev_default_fork */ 1457 postfork = 1; /* must be in line with ev_default_fork */
1371} 1458}
1372
1373#endif 1459#endif
1374 1460
1375#if EV_MULTIPLICITY 1461#if EV_MULTIPLICITY
1376struct ev_loop * 1462struct ev_loop *
1377ev_default_loop_init (unsigned int flags) 1463ev_default_loop_init (unsigned int flags)
1458 EV_CB_INVOKE (p->w, p->events); 1544 EV_CB_INVOKE (p->w, p->events);
1459 } 1545 }
1460 } 1546 }
1461} 1547}
1462 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
1463void inline_size 1572void inline_size
1464timers_reify (EV_P) 1573timers_reify (EV_P)
1465{ 1574{
1466 while (timercnt && ev_at (timers [1]) <= mn_now) 1575 while (timercnt && ev_at (timers [HEAP0]) <= mn_now)
1467 { 1576 {
1468 ev_timer *w = (ev_timer *)timers [1]; 1577 ev_timer *w = (ev_timer *)timers [HEAP0];
1469 1578
1470 /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ 1579 /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/
1471 1580
1472 /* first reschedule or stop timer */ 1581 /* first reschedule or stop timer */
1473 if (w->repeat) 1582 if (w->repeat)
1476 1585
1477 ev_at (w) += w->repeat; 1586 ev_at (w) += w->repeat;
1478 if (ev_at (w) < mn_now) 1587 if (ev_at (w) < mn_now)
1479 ev_at (w) = mn_now; 1588 ev_at (w) = mn_now;
1480 1589
1481 downheap (timers, timercnt, 1); 1590 downheap (timers, timercnt, HEAP0);
1482 } 1591 }
1483 else 1592 else
1484 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ 1593 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
1485 1594
1486 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); 1595 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT);
1489 1598
1490#if EV_PERIODIC_ENABLE 1599#if EV_PERIODIC_ENABLE
1491void inline_size 1600void inline_size
1492periodics_reify (EV_P) 1601periodics_reify (EV_P)
1493{ 1602{
1494 while (periodiccnt && ev_at (periodics [1]) <= ev_rt_now) 1603 while (periodiccnt && ev_at (periodics [HEAP0]) <= ev_rt_now)
1495 { 1604 {
1496 ev_periodic *w = (ev_periodic *)periodics [1]; 1605 ev_periodic *w = (ev_periodic *)periodics [HEAP0];
1497 1606
1498 /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ 1607 /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/
1499 1608
1500 /* first reschedule or stop timer */ 1609 /* first reschedule or stop timer */
1501 if (w->reschedule_cb) 1610 if (w->reschedule_cb)
1507 else if (w->interval) 1616 else if (w->interval)
1508 { 1617 {
1509 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;
1510 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;
1511 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));
1512 downheap (periodics, periodiccnt, 1); 1621 downheap (periodics, periodiccnt, HEAP0);
1513 } 1622 }
1514 else 1623 else
1515 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ 1624 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
1516 1625
1517 ev_feed_event (EV_A_ (W)w, EV_PERIODIC); 1626 ev_feed_event (EV_A_ (W)w, EV_PERIODIC);
1522periodics_reschedule (EV_P) 1631periodics_reschedule (EV_P)
1523{ 1632{
1524 int i; 1633 int i;
1525 1634
1526 /* adjust periodics after time jump */ 1635 /* adjust periodics after time jump */
1527 for (i = 0; i < periodiccnt; ++i) 1636 for (i = 1; i <= periodiccnt; ++i)
1528 { 1637 {
1529 ev_periodic *w = (ev_periodic *)periodics [i]; 1638 ev_periodic *w = (ev_periodic *)periodics [i];
1530 1639
1531 if (w->reschedule_cb) 1640 if (w->reschedule_cb)
1532 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 1641 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
1533 else if (w->interval) 1642 else if (w->interval)
1534 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;
1535 } 1644 }
1536 1645
1537 /* now rebuild the heap */ 1646 /* now rebuild the heap */
1538 for (i = periodiccnt >> 1; i--; ) 1647 for (i = periodiccnt >> 1; --i; )
1539 downheap (periodics, periodiccnt, i); 1648 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} 1649}
1564#endif 1650#endif
1565 1651
1566void inline_speed 1652void inline_speed
1567time_update (EV_P_ ev_tstamp max_block) 1653time_update (EV_P_ ev_tstamp max_block)
1596 */ 1682 */
1597 for (i = 4; --i; ) 1683 for (i = 4; --i; )
1598 { 1684 {
1599 rtmn_diff = ev_rt_now - mn_now; 1685 rtmn_diff = ev_rt_now - mn_now;
1600 1686
1601 if (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP) 1687 if (expect_true (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP))
1602 return; /* all is well */ 1688 return; /* all is well */
1603 1689
1604 ev_rt_now = ev_time (); 1690 ev_rt_now = ev_time ();
1605 mn_now = get_clock (); 1691 mn_now = get_clock ();
1606 now_floor = mn_now; 1692 now_floor = mn_now;
1702 1788
1703 waittime = MAX_BLOCKTIME; 1789 waittime = MAX_BLOCKTIME;
1704 1790
1705 if (timercnt) 1791 if (timercnt)
1706 { 1792 {
1707 ev_tstamp to = ev_at (timers [1]) - mn_now + backend_fudge; 1793 ev_tstamp to = ev_at (timers [HEAP0]) - mn_now + backend_fudge;
1708 if (waittime > to) waittime = to; 1794 if (waittime > to) waittime = to;
1709 } 1795 }
1710 1796
1711#if EV_PERIODIC_ENABLE 1797#if EV_PERIODIC_ENABLE
1712 if (periodiccnt) 1798 if (periodiccnt)
1713 { 1799 {
1714 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;
1715 if (waittime > to) waittime = to; 1801 if (waittime > to) waittime = to;
1716 } 1802 }
1717#endif 1803#endif
1718 1804
1719 if (expect_false (waittime < timeout_blocktime)) 1805 if (expect_false (waittime < timeout_blocktime))
1889 1975
1890 ev_at (w) += mn_now; 1976 ev_at (w) += mn_now;
1891 1977
1892 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.));
1893 1979
1894 ev_start (EV_A_ (W)w, ++timercnt); 1980 ev_start (EV_A_ (W)w, ++timercnt + HEAP0 - 1);
1895 array_needsize (WT, timers, timermax, timercnt + 1, EMPTY2); 1981 array_needsize (WT, timers, timermax, timercnt + HEAP0, EMPTY2);
1896 timers [timercnt] = (WT)w; 1982 timers [ev_active (w)] = (WT)w;
1897 upheap (timers, timercnt); 1983 upheap (timers, ev_active (w));
1898 1984
1899 /*assert (("internal timer heap corruption", timers [((W)w)->active] == w));*/ 1985 /*assert (("internal timer heap corruption", timers [ev_active (w)] == w));*/
1900} 1986}
1901 1987
1902void noinline 1988void noinline
1903ev_timer_stop (EV_P_ ev_timer *w) 1989ev_timer_stop (EV_P_ ev_timer *w)
1904{ 1990{
1905 clear_pending (EV_A_ (W)w); 1991 clear_pending (EV_A_ (W)w);
1906 if (expect_false (!ev_is_active (w))) 1992 if (expect_false (!ev_is_active (w)))
1907 return; 1993 return;
1908 1994
1909 assert (("internal timer heap corruption", timers [((W)w)->active] == (WT)w));
1910
1911 { 1995 {
1912 int active = ((W)w)->active; 1996 int active = ev_active (w);
1913 1997
1998 assert (("internal timer heap corruption", timers [active] == (WT)w));
1999
1914 if (expect_true (active < timercnt)) 2000 if (expect_true (active < timercnt + HEAP0 - 1))
1915 { 2001 {
1916 timers [active] = timers [timercnt]; 2002 timers [active] = timers [timercnt + HEAP0 - 1];
1917 adjustheap (timers, timercnt, active); 2003 adjustheap (timers, timercnt, active);
1918 } 2004 }
1919 2005
1920 --timercnt; 2006 --timercnt;
1921 } 2007 }
1931 if (ev_is_active (w)) 2017 if (ev_is_active (w))
1932 { 2018 {
1933 if (w->repeat) 2019 if (w->repeat)
1934 { 2020 {
1935 ev_at (w) = mn_now + w->repeat; 2021 ev_at (w) = mn_now + w->repeat;
1936 adjustheap (timers, timercnt, ((W)w)->active); 2022 adjustheap (timers, timercnt, ev_active (w));
1937 } 2023 }
1938 else 2024 else
1939 ev_timer_stop (EV_A_ w); 2025 ev_timer_stop (EV_A_ w);
1940 } 2026 }
1941 else if (w->repeat) 2027 else if (w->repeat)
1942 { 2028 {
1943 w->at = w->repeat; 2029 ev_at (w) = w->repeat;
1944 ev_timer_start (EV_A_ w); 2030 ev_timer_start (EV_A_ w);
1945 } 2031 }
1946} 2032}
1947 2033
1948#if EV_PERIODIC_ENABLE 2034#if EV_PERIODIC_ENABLE
1961 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;
1962 } 2048 }
1963 else 2049 else
1964 ev_at (w) = w->offset; 2050 ev_at (w) = w->offset;
1965 2051
1966 ev_start (EV_A_ (W)w, ++periodiccnt); 2052 ev_start (EV_A_ (W)w, ++periodiccnt + HEAP0 - 1);
1967 array_needsize (WT, periodics, periodicmax, periodiccnt + 1, EMPTY2); 2053 array_needsize (WT, periodics, periodicmax, periodiccnt + HEAP0, EMPTY2);
1968 periodics [periodiccnt] = (WT)w; 2054 periodics [ev_active (w)] = (WT)w;
1969 upheap (periodics, periodiccnt); 2055 upheap (periodics, ev_active (w));
1970 2056
1971 /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ 2057 /*assert (("internal periodic heap corruption", periodics [ev_active (w)] == w));*/
1972} 2058}
1973 2059
1974void noinline 2060void noinline
1975ev_periodic_stop (EV_P_ ev_periodic *w) 2061ev_periodic_stop (EV_P_ ev_periodic *w)
1976{ 2062{
1977 clear_pending (EV_A_ (W)w); 2063 clear_pending (EV_A_ (W)w);
1978 if (expect_false (!ev_is_active (w))) 2064 if (expect_false (!ev_is_active (w)))
1979 return; 2065 return;
1980 2066
1981 assert (("internal periodic heap corruption", periodics [((W)w)->active] == (WT)w));
1982
1983 { 2067 {
1984 int active = ((W)w)->active; 2068 int active = ev_active (w);
1985 2069
2070 assert (("internal periodic heap corruption", periodics [active] == (WT)w));
2071
1986 if (expect_true (active < periodiccnt)) 2072 if (expect_true (active < periodiccnt + HEAP0 - 1))
1987 { 2073 {
1988 periodics [active] = periodics [periodiccnt]; 2074 periodics [active] = periodics [periodiccnt + HEAP0 - 1];
1989 adjustheap (periodics, periodiccnt, active); 2075 adjustheap (periodics, periodiccnt, active);
1990 } 2076 }
1991 2077
1992 --periodiccnt; 2078 --periodiccnt;
1993 } 2079 }
2113 if (w->wd < 0) 2199 if (w->wd < 0)
2114 { 2200 {
2115 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 */
2116 2202
2117 /* 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 */
2118 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) 2206 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096)
2119 { 2207 {
2120 char path [4096]; 2208 char path [4096];
2121 strcpy (path, w->path); 2209 strcpy (path, w->path);
2122 2210
2367 clear_pending (EV_A_ (W)w); 2455 clear_pending (EV_A_ (W)w);
2368 if (expect_false (!ev_is_active (w))) 2456 if (expect_false (!ev_is_active (w)))
2369 return; 2457 return;
2370 2458
2371 { 2459 {
2372 int active = ((W)w)->active; 2460 int active = ev_active (w);
2373 2461
2374 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; 2462 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]];
2375 ((W)idles [ABSPRI (w)][active - 1])->active = active; 2463 ev_active (idles [ABSPRI (w)][active - 1]) = active;
2376 2464
2377 ev_stop (EV_A_ (W)w); 2465 ev_stop (EV_A_ (W)w);
2378 --idleall; 2466 --idleall;
2379 } 2467 }
2380} 2468}
2397 clear_pending (EV_A_ (W)w); 2485 clear_pending (EV_A_ (W)w);
2398 if (expect_false (!ev_is_active (w))) 2486 if (expect_false (!ev_is_active (w)))
2399 return; 2487 return;
2400 2488
2401 { 2489 {
2402 int active = ((W)w)->active; 2490 int active = ev_active (w);
2491
2403 prepares [active - 1] = prepares [--preparecnt]; 2492 prepares [active - 1] = prepares [--preparecnt];
2404 ((W)prepares [active - 1])->active = active; 2493 ev_active (prepares [active - 1]) = active;
2405 } 2494 }
2406 2495
2407 ev_stop (EV_A_ (W)w); 2496 ev_stop (EV_A_ (W)w);
2408} 2497}
2409 2498
2424 clear_pending (EV_A_ (W)w); 2513 clear_pending (EV_A_ (W)w);
2425 if (expect_false (!ev_is_active (w))) 2514 if (expect_false (!ev_is_active (w)))
2426 return; 2515 return;
2427 2516
2428 { 2517 {
2429 int active = ((W)w)->active; 2518 int active = ev_active (w);
2519
2430 checks [active - 1] = checks [--checkcnt]; 2520 checks [active - 1] = checks [--checkcnt];
2431 ((W)checks [active - 1])->active = active; 2521 ev_active (checks [active - 1]) = active;
2432 } 2522 }
2433 2523
2434 ev_stop (EV_A_ (W)w); 2524 ev_stop (EV_A_ (W)w);
2435} 2525}
2436 2526
2532 clear_pending (EV_A_ (W)w); 2622 clear_pending (EV_A_ (W)w);
2533 if (expect_false (!ev_is_active (w))) 2623 if (expect_false (!ev_is_active (w)))
2534 return; 2624 return;
2535 2625
2536 { 2626 {
2537 int active = ((W)w)->active; 2627 int active = ev_active (w);
2628
2538 forks [active - 1] = forks [--forkcnt]; 2629 forks [active - 1] = forks [--forkcnt];
2539 ((W)forks [active - 1])->active = active; 2630 ev_active (forks [active - 1]) = active;
2540 } 2631 }
2541 2632
2542 ev_stop (EV_A_ (W)w); 2633 ev_stop (EV_A_ (W)w);
2543} 2634}
2544#endif 2635#endif
2563 clear_pending (EV_A_ (W)w); 2654 clear_pending (EV_A_ (W)w);
2564 if (expect_false (!ev_is_active (w))) 2655 if (expect_false (!ev_is_active (w)))
2565 return; 2656 return;
2566 2657
2567 { 2658 {
2568 int active = ((W)w)->active; 2659 int active = ev_active (w);
2660
2569 asyncs [active - 1] = asyncs [--asynccnt]; 2661 asyncs [active - 1] = asyncs [--asynccnt];
2570 ((W)asyncs [active - 1])->active = active; 2662 ev_active (asyncs [active - 1]) = active;
2571 } 2663 }
2572 2664
2573 ev_stop (EV_A_ (W)w); 2665 ev_stop (EV_A_ (W)w);
2574} 2666}
2575 2667

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines