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

Comparing libev/ev.c (file contents):
Revision 1.225 by root, Wed Apr 16 01:37:14 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;
754 } 759 }
755} 760}
756 761
757/*****************************************************************************/ 762/*****************************************************************************/
758 763
764/* towards the root */
759void inline_speed 765void inline_speed
760upheap (WT *heap, int k) 766upheap (WT *heap, int k)
761{ 767{
762 WT w = heap [k]; 768 WT w = heap [k];
763 769
764 while (k) 770 for (;;)
765 { 771 {
766 int p = (k - 1) >> 1; 772 int p = k >> 1;
767 773
774 /* maybe we could use a dummy element at heap [0]? */
768 if (heap [p]->at <= w->at) 775 if (!p || heap [p]->at <= w->at)
769 break; 776 break;
770 777
771 heap [k] = heap [p]; 778 heap [k] = heap [p];
772 ((W)heap [k])->active = k + 1; 779 ev_active (heap [k]) = k;
773 k = p; 780 k = p;
774 } 781 }
775 782
776 heap [k] = w; 783 heap [k] = w;
777 ((W)heap [k])->active = k + 1; 784 ev_active (heap [k]) = k;
778} 785}
779 786
787/* away from the root */
780void inline_speed 788void inline_speed
781downheap (WT *heap, int N, int k) 789downheap (WT *heap, int N, int k)
782{ 790{
783 WT w = heap [k]; 791 WT w = heap [k];
784 792
785 for (;;) 793 for (;;)
786 { 794 {
787 int c = (k << 1) + 1; 795 int c = k << 1;
788 796
789 if (c >= N) 797 if (c > N)
790 break; 798 break;
791 799
792 c += c + 1 < N && heap [c]->at > heap [c + 1]->at 800 c += c < N && heap [c]->at > heap [c + 1]->at
793 ? 1 : 0; 801 ? 1 : 0;
794 802
795 if (w->at <= heap [c]->at) 803 if (w->at <= heap [c]->at)
796 break; 804 break;
797 805
798 heap [k] = heap [c]; 806 heap [k] = heap [c];
799 ((W)heap [k])->active = k + 1; 807 ev_active (heap [k]) = k;
800 808
801 k = c; 809 k = c;
802 } 810 }
803 811
804 heap [k] = w; 812 heap [k] = w;
805 ((W)heap [k])->active = k + 1; 813 ev_active (heap [k]) = k;
806} 814}
807 815
808void inline_size 816void inline_size
809adjustheap (WT *heap, int N, int k) 817adjustheap (WT *heap, int N, int k)
810{ 818{
906pipecb (EV_P_ ev_io *iow, int revents) 914pipecb (EV_P_ ev_io *iow, int revents)
907{ 915{
908#if EV_USE_EVENTFD 916#if EV_USE_EVENTFD
909 if (evfd >= 0) 917 if (evfd >= 0)
910 { 918 {
911 uint64_t counter = 1; 919 uint64_t counter;
912 read (evfd, &counter, sizeof (uint64_t)); 920 read (evfd, &counter, sizeof (uint64_t));
913 } 921 }
914 else 922 else
915#endif 923#endif
916 { 924 {
1283#endif 1291#endif
1284 1292
1285 backend = 0; 1293 backend = 0;
1286} 1294}
1287 1295
1296#if EV_USE_INOTIFY
1288void inline_size infy_fork (EV_P); 1297void inline_size infy_fork (EV_P);
1298#endif
1289 1299
1290void inline_size 1300void inline_size
1291loop_fork (EV_P) 1301loop_fork (EV_P)
1292{ 1302{
1293#if EV_USE_PORT 1303#if EV_USE_PORT
1360void 1370void
1361ev_loop_fork (EV_P) 1371ev_loop_fork (EV_P)
1362{ 1372{
1363 postfork = 1; /* must be in line with ev_default_fork */ 1373 postfork = 1; /* must be in line with ev_default_fork */
1364} 1374}
1365
1366#endif 1375#endif
1367 1376
1368#if EV_MULTIPLICITY 1377#if EV_MULTIPLICITY
1369struct ev_loop * 1378struct ev_loop *
1370ev_default_loop_init (unsigned int flags) 1379ev_default_loop_init (unsigned int flags)
1451 EV_CB_INVOKE (p->w, p->events); 1460 EV_CB_INVOKE (p->w, p->events);
1452 } 1461 }
1453 } 1462 }
1454} 1463}
1455 1464
1456void inline_size
1457timers_reify (EV_P)
1458{
1459 while (timercnt && ((WT)timers [0])->at <= mn_now)
1460 {
1461 ev_timer *w = (ev_timer *)timers [0];
1462
1463 /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/
1464
1465 /* first reschedule or stop timer */
1466 if (w->repeat)
1467 {
1468 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.));
1469
1470 ((WT)w)->at += w->repeat;
1471 if (((WT)w)->at < mn_now)
1472 ((WT)w)->at = mn_now;
1473
1474 downheap (timers, timercnt, 0);
1475 }
1476 else
1477 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
1478
1479 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT);
1480 }
1481}
1482
1483#if EV_PERIODIC_ENABLE
1484void inline_size
1485periodics_reify (EV_P)
1486{
1487 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now)
1488 {
1489 ev_periodic *w = (ev_periodic *)periodics [0];
1490
1491 /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/
1492
1493 /* first reschedule or stop timer */
1494 if (w->reschedule_cb)
1495 {
1496 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + TIME_EPSILON);
1497 assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now));
1498 downheap (periodics, periodiccnt, 0);
1499 }
1500 else if (w->interval)
1501 {
1502 ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1503 if (((WT)w)->at - ev_rt_now <= TIME_EPSILON) ((WT)w)->at += w->interval;
1504 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now));
1505 downheap (periodics, periodiccnt, 0);
1506 }
1507 else
1508 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
1509
1510 ev_feed_event (EV_A_ (W)w, EV_PERIODIC);
1511 }
1512}
1513
1514static void noinline
1515periodics_reschedule (EV_P)
1516{
1517 int i;
1518
1519 /* adjust periodics after time jump */
1520 for (i = 0; i < periodiccnt; ++i)
1521 {
1522 ev_periodic *w = (ev_periodic *)periodics [i];
1523
1524 if (w->reschedule_cb)
1525 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now);
1526 else if (w->interval)
1527 ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1528 }
1529
1530 /* now rebuild the heap */
1531 for (i = periodiccnt >> 1; i--; )
1532 downheap (periodics, periodiccnt, i);
1533}
1534#endif
1535
1536#if EV_IDLE_ENABLE 1465#if EV_IDLE_ENABLE
1537void inline_size 1466void inline_size
1538idle_reify (EV_P) 1467idle_reify (EV_P)
1539{ 1468{
1540 if (expect_false (idleall)) 1469 if (expect_false (idleall))
1551 queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE); 1480 queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE);
1552 break; 1481 break;
1553 } 1482 }
1554 } 1483 }
1555 } 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);
1556} 1565}
1557#endif 1566#endif
1558 1567
1559void inline_speed 1568void inline_speed
1560time_update (EV_P_ ev_tstamp max_block) 1569time_update (EV_P_ ev_tstamp max_block)
1589 */ 1598 */
1590 for (i = 4; --i; ) 1599 for (i = 4; --i; )
1591 { 1600 {
1592 rtmn_diff = ev_rt_now - mn_now; 1601 rtmn_diff = ev_rt_now - mn_now;
1593 1602
1594 if (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP) 1603 if (expect_true (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP))
1595 return; /* all is well */ 1604 return; /* all is well */
1596 1605
1597 ev_rt_now = ev_time (); 1606 ev_rt_now = ev_time ();
1598 mn_now = get_clock (); 1607 mn_now = get_clock ();
1599 now_floor = mn_now; 1608 now_floor = mn_now;
1614 { 1623 {
1615#if EV_PERIODIC_ENABLE 1624#if EV_PERIODIC_ENABLE
1616 periodics_reschedule (EV_A); 1625 periodics_reschedule (EV_A);
1617#endif 1626#endif
1618 /* 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 */
1619 for (i = 0; i < timercnt; ++i) 1628 for (i = 1; i <= timercnt; ++i)
1620 ((WT)timers [i])->at += ev_rt_now - mn_now; 1629 ev_at (timers [i]) += ev_rt_now - mn_now;
1621 } 1630 }
1622 1631
1623 mn_now = ev_rt_now; 1632 mn_now = ev_rt_now;
1624 } 1633 }
1625} 1634}
1695 1704
1696 waittime = MAX_BLOCKTIME; 1705 waittime = MAX_BLOCKTIME;
1697 1706
1698 if (timercnt) 1707 if (timercnt)
1699 { 1708 {
1700 ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge; 1709 ev_tstamp to = ev_at (timers [1]) - mn_now + backend_fudge;
1701 if (waittime > to) waittime = to; 1710 if (waittime > to) waittime = to;
1702 } 1711 }
1703 1712
1704#if EV_PERIODIC_ENABLE 1713#if EV_PERIODIC_ENABLE
1705 if (periodiccnt) 1714 if (periodiccnt)
1706 { 1715 {
1707 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;
1708 if (waittime > to) waittime = to; 1717 if (waittime > to) waittime = to;
1709 } 1718 }
1710#endif 1719#endif
1711 1720
1712 if (expect_false (waittime < timeout_blocktime)) 1721 if (expect_false (waittime < timeout_blocktime))
1878ev_timer_start (EV_P_ ev_timer *w) 1887ev_timer_start (EV_P_ ev_timer *w)
1879{ 1888{
1880 if (expect_false (ev_is_active (w))) 1889 if (expect_false (ev_is_active (w)))
1881 return; 1890 return;
1882 1891
1883 ((WT)w)->at += mn_now; 1892 ev_at (w) += mn_now;
1884 1893
1885 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.));
1886 1895
1887 ev_start (EV_A_ (W)w, ++timercnt); 1896 ev_start (EV_A_ (W)w, ++timercnt);
1888 array_needsize (WT, timers, timermax, timercnt, EMPTY2); 1897 array_needsize (WT, timers, timermax, timercnt + 1, EMPTY2);
1889 timers [timercnt - 1] = (WT)w; 1898 timers [timercnt] = (WT)w;
1890 upheap (timers, timercnt - 1); 1899 upheap (timers, timercnt);
1891 1900
1892 /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ 1901 /*assert (("internal timer heap corruption", timers [ev_active (w)] == w));*/
1893} 1902}
1894 1903
1895void noinline 1904void noinline
1896ev_timer_stop (EV_P_ ev_timer *w) 1905ev_timer_stop (EV_P_ ev_timer *w)
1897{ 1906{
1898 clear_pending (EV_A_ (W)w); 1907 clear_pending (EV_A_ (W)w);
1899 if (expect_false (!ev_is_active (w))) 1908 if (expect_false (!ev_is_active (w)))
1900 return; 1909 return;
1901 1910
1902 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == (WT)w));
1903
1904 { 1911 {
1905 int active = ((W)w)->active; 1912 int active = ev_active (w);
1906 1913
1914 assert (("internal timer heap corruption", timers [active] == (WT)w));
1915
1907 if (expect_true (--active < --timercnt)) 1916 if (expect_true (active < timercnt))
1908 { 1917 {
1909 timers [active] = timers [timercnt]; 1918 timers [active] = timers [timercnt];
1910 adjustheap (timers, timercnt, active); 1919 adjustheap (timers, timercnt, active);
1911 } 1920 }
1921
1922 --timercnt;
1912 } 1923 }
1913 1924
1914 ((WT)w)->at -= mn_now; 1925 ev_at (w) -= mn_now;
1915 1926
1916 ev_stop (EV_A_ (W)w); 1927 ev_stop (EV_A_ (W)w);
1917} 1928}
1918 1929
1919void noinline 1930void noinline
1921{ 1932{
1922 if (ev_is_active (w)) 1933 if (ev_is_active (w))
1923 { 1934 {
1924 if (w->repeat) 1935 if (w->repeat)
1925 { 1936 {
1926 ((WT)w)->at = mn_now + w->repeat; 1937 ev_at (w) = mn_now + w->repeat;
1927 adjustheap (timers, timercnt, ((W)w)->active - 1); 1938 adjustheap (timers, timercnt, ev_active (w));
1928 } 1939 }
1929 else 1940 else
1930 ev_timer_stop (EV_A_ w); 1941 ev_timer_stop (EV_A_ w);
1931 } 1942 }
1932 else if (w->repeat) 1943 else if (w->repeat)
1933 { 1944 {
1934 w->at = w->repeat; 1945 ev_at (w) = w->repeat;
1935 ev_timer_start (EV_A_ w); 1946 ev_timer_start (EV_A_ w);
1936 } 1947 }
1937} 1948}
1938 1949
1939#if EV_PERIODIC_ENABLE 1950#if EV_PERIODIC_ENABLE
1942{ 1953{
1943 if (expect_false (ev_is_active (w))) 1954 if (expect_false (ev_is_active (w)))
1944 return; 1955 return;
1945 1956
1946 if (w->reschedule_cb) 1957 if (w->reschedule_cb)
1947 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); 1958 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
1948 else if (w->interval) 1959 else if (w->interval)
1949 { 1960 {
1950 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.));
1951 /* 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 */
1952 ((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;
1953 } 1964 }
1954 else 1965 else
1955 ((WT)w)->at = w->offset; 1966 ev_at (w) = w->offset;
1956 1967
1957 ev_start (EV_A_ (W)w, ++periodiccnt); 1968 ev_start (EV_A_ (W)w, ++periodiccnt);
1958 array_needsize (WT, periodics, periodicmax, periodiccnt, EMPTY2); 1969 array_needsize (WT, periodics, periodicmax, periodiccnt + 1, EMPTY2);
1959 periodics [periodiccnt - 1] = (WT)w; 1970 periodics [periodiccnt] = (WT)w;
1960 upheap (periodics, periodiccnt - 1); 1971 upheap (periodics, periodiccnt);
1961 1972
1962 /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ 1973 /*assert (("internal periodic heap corruption", periodics [ev_active (w)] == w));*/
1963} 1974}
1964 1975
1965void noinline 1976void noinline
1966ev_periodic_stop (EV_P_ ev_periodic *w) 1977ev_periodic_stop (EV_P_ ev_periodic *w)
1967{ 1978{
1968 clear_pending (EV_A_ (W)w); 1979 clear_pending (EV_A_ (W)w);
1969 if (expect_false (!ev_is_active (w))) 1980 if (expect_false (!ev_is_active (w)))
1970 return; 1981 return;
1971 1982
1972 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == (WT)w));
1973
1974 { 1983 {
1975 int active = ((W)w)->active; 1984 int active = ev_active (w);
1976 1985
1986 assert (("internal periodic heap corruption", periodics [active] == (WT)w));
1987
1977 if (expect_true (--active < --periodiccnt)) 1988 if (expect_true (active < periodiccnt))
1978 { 1989 {
1979 periodics [active] = periodics [periodiccnt]; 1990 periodics [active] = periodics [periodiccnt];
1980 adjustheap (periodics, periodiccnt, active); 1991 adjustheap (periodics, periodiccnt, active);
1981 } 1992 }
1993
1994 --periodiccnt;
1982 } 1995 }
1983 1996
1984 ev_stop (EV_A_ (W)w); 1997 ev_stop (EV_A_ (W)w);
1985} 1998}
1986 1999
2102 if (w->wd < 0) 2115 if (w->wd < 0)
2103 { 2116 {
2104 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 */
2105 2118
2106 /* 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 */
2107 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) 2122 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096)
2108 { 2123 {
2109 char path [4096]; 2124 char path [4096];
2110 strcpy (path, w->path); 2125 strcpy (path, w->path);
2111 2126
2356 clear_pending (EV_A_ (W)w); 2371 clear_pending (EV_A_ (W)w);
2357 if (expect_false (!ev_is_active (w))) 2372 if (expect_false (!ev_is_active (w)))
2358 return; 2373 return;
2359 2374
2360 { 2375 {
2361 int active = ((W)w)->active; 2376 int active = ev_active (w);
2362 2377
2363 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; 2378 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]];
2364 ((W)idles [ABSPRI (w)][active - 1])->active = active; 2379 ev_active (idles [ABSPRI (w)][active - 1]) = active;
2365 2380
2366 ev_stop (EV_A_ (W)w); 2381 ev_stop (EV_A_ (W)w);
2367 --idleall; 2382 --idleall;
2368 } 2383 }
2369} 2384}
2386 clear_pending (EV_A_ (W)w); 2401 clear_pending (EV_A_ (W)w);
2387 if (expect_false (!ev_is_active (w))) 2402 if (expect_false (!ev_is_active (w)))
2388 return; 2403 return;
2389 2404
2390 { 2405 {
2391 int active = ((W)w)->active; 2406 int active = ev_active (w);
2407
2392 prepares [active - 1] = prepares [--preparecnt]; 2408 prepares [active - 1] = prepares [--preparecnt];
2393 ((W)prepares [active - 1])->active = active; 2409 ev_active (prepares [active - 1]) = active;
2394 } 2410 }
2395 2411
2396 ev_stop (EV_A_ (W)w); 2412 ev_stop (EV_A_ (W)w);
2397} 2413}
2398 2414
2413 clear_pending (EV_A_ (W)w); 2429 clear_pending (EV_A_ (W)w);
2414 if (expect_false (!ev_is_active (w))) 2430 if (expect_false (!ev_is_active (w)))
2415 return; 2431 return;
2416 2432
2417 { 2433 {
2418 int active = ((W)w)->active; 2434 int active = ev_active (w);
2435
2419 checks [active - 1] = checks [--checkcnt]; 2436 checks [active - 1] = checks [--checkcnt];
2420 ((W)checks [active - 1])->active = active; 2437 ev_active (checks [active - 1]) = active;
2421 } 2438 }
2422 2439
2423 ev_stop (EV_A_ (W)w); 2440 ev_stop (EV_A_ (W)w);
2424} 2441}
2425 2442
2521 clear_pending (EV_A_ (W)w); 2538 clear_pending (EV_A_ (W)w);
2522 if (expect_false (!ev_is_active (w))) 2539 if (expect_false (!ev_is_active (w)))
2523 return; 2540 return;
2524 2541
2525 { 2542 {
2526 int active = ((W)w)->active; 2543 int active = ev_active (w);
2544
2527 forks [active - 1] = forks [--forkcnt]; 2545 forks [active - 1] = forks [--forkcnt];
2528 ((W)forks [active - 1])->active = active; 2546 ev_active (forks [active - 1]) = active;
2529 } 2547 }
2530 2548
2531 ev_stop (EV_A_ (W)w); 2549 ev_stop (EV_A_ (W)w);
2532} 2550}
2533#endif 2551#endif
2552 clear_pending (EV_A_ (W)w); 2570 clear_pending (EV_A_ (W)w);
2553 if (expect_false (!ev_is_active (w))) 2571 if (expect_false (!ev_is_active (w)))
2554 return; 2572 return;
2555 2573
2556 { 2574 {
2557 int active = ((W)w)->active; 2575 int active = ev_active (w);
2576
2558 asyncs [active - 1] = asyncs [--asynccnt]; 2577 asyncs [active - 1] = asyncs [--asynccnt];
2559 ((W)asyncs [active - 1])->active = active; 2578 ev_active (asyncs [active - 1]) = active;
2560 } 2579 }
2561 2580
2562 ev_stop (EV_A_ (W)w); 2581 ev_stop (EV_A_ (W)w);
2563} 2582}
2564 2583

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines