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.233 by root, Tue May 6 23:34: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
1454} 1464}
1455 1465
1456void inline_size 1466void inline_size
1457timers_reify (EV_P) 1467timers_reify (EV_P)
1458{ 1468{
1459 while (timercnt && ((WT)timers [0])->at <= mn_now) 1469 while (timercnt && ev_at (timers [1]) <= mn_now)
1460 { 1470 {
1461 ev_timer *w = (ev_timer *)timers [0]; 1471 ev_timer *w = (ev_timer *)timers [1];
1462 1472
1463 /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ 1473 /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/
1464 1474
1465 /* first reschedule or stop timer */ 1475 /* first reschedule or stop timer */
1466 if (w->repeat) 1476 if (w->repeat)
1467 { 1477 {
1468 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); 1478 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.));
1469 1479
1470 ((WT)w)->at += w->repeat; 1480 ev_at (w) += w->repeat;
1471 if (((WT)w)->at < mn_now) 1481 if (ev_at (w) < mn_now)
1472 ((WT)w)->at = mn_now; 1482 ev_at (w) = mn_now;
1473 1483
1474 downheap (timers, timercnt, 0); 1484 downheap (timers, timercnt, 1);
1475 } 1485 }
1476 else 1486 else
1477 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ 1487 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
1478 1488
1479 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); 1489 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT);
1482 1492
1483#if EV_PERIODIC_ENABLE 1493#if EV_PERIODIC_ENABLE
1484void inline_size 1494void inline_size
1485periodics_reify (EV_P) 1495periodics_reify (EV_P)
1486{ 1496{
1487 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) 1497 while (periodiccnt && ev_at (periodics [1]) <= ev_rt_now)
1488 { 1498 {
1489 ev_periodic *w = (ev_periodic *)periodics [0]; 1499 ev_periodic *w = (ev_periodic *)periodics [1];
1490 1500
1491 /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ 1501 /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/
1492 1502
1493 /* first reschedule or stop timer */ 1503 /* first reschedule or stop timer */
1494 if (w->reschedule_cb) 1504 if (w->reschedule_cb)
1495 { 1505 {
1496 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + TIME_EPSILON); 1506 ev_at (w) = 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)); 1507 assert (("ev_periodic reschedule callback returned time in the past", ev_at (w) > ev_rt_now));
1498 downheap (periodics, periodiccnt, 0); 1508 downheap (periodics, periodiccnt, 1);
1499 } 1509 }
1500 else if (w->interval) 1510 else if (w->interval)
1501 { 1511 {
1502 ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 1512 ev_at (w) = 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; 1513 if (ev_at (w) - ev_rt_now <= TIME_EPSILON) ev_at (w) += w->interval;
1504 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now)); 1514 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ev_at (w) > ev_rt_now));
1505 downheap (periodics, periodiccnt, 0); 1515 downheap (periodics, periodiccnt, 1);
1506 } 1516 }
1507 else 1517 else
1508 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ 1518 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
1509 1519
1510 ev_feed_event (EV_A_ (W)w, EV_PERIODIC); 1520 ev_feed_event (EV_A_ (W)w, EV_PERIODIC);
1515periodics_reschedule (EV_P) 1525periodics_reschedule (EV_P)
1516{ 1526{
1517 int i; 1527 int i;
1518 1528
1519 /* adjust periodics after time jump */ 1529 /* adjust periodics after time jump */
1520 for (i = 0; i < periodiccnt; ++i) 1530 for (i = 1; i <= periodiccnt; ++i)
1521 { 1531 {
1522 ev_periodic *w = (ev_periodic *)periodics [i]; 1532 ev_periodic *w = (ev_periodic *)periodics [i];
1523 1533
1524 if (w->reschedule_cb) 1534 if (w->reschedule_cb)
1525 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); 1535 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
1526 else if (w->interval) 1536 else if (w->interval)
1527 ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 1537 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1528 } 1538 }
1529 1539
1530 /* now rebuild the heap */ 1540 /* now rebuild the heap */
1531 for (i = periodiccnt >> 1; i--; ) 1541 for (i = periodiccnt >> 1; i--; )
1532 downheap (periodics, periodiccnt, i); 1542 downheap (periodics, periodiccnt, i);
1614 { 1624 {
1615#if EV_PERIODIC_ENABLE 1625#if EV_PERIODIC_ENABLE
1616 periodics_reschedule (EV_A); 1626 periodics_reschedule (EV_A);
1617#endif 1627#endif
1618 /* adjust timers. this is easy, as the offset is the same for all of them */ 1628 /* adjust timers. this is easy, as the offset is the same for all of them */
1619 for (i = 0; i < timercnt; ++i) 1629 for (i = 1; i <= timercnt; ++i)
1620 ((WT)timers [i])->at += ev_rt_now - mn_now; 1630 ev_at (timers [i]) += ev_rt_now - mn_now;
1621 } 1631 }
1622 1632
1623 mn_now = ev_rt_now; 1633 mn_now = ev_rt_now;
1624 } 1634 }
1625} 1635}
1695 1705
1696 waittime = MAX_BLOCKTIME; 1706 waittime = MAX_BLOCKTIME;
1697 1707
1698 if (timercnt) 1708 if (timercnt)
1699 { 1709 {
1700 ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge; 1710 ev_tstamp to = ev_at (timers [1]) - mn_now + backend_fudge;
1701 if (waittime > to) waittime = to; 1711 if (waittime > to) waittime = to;
1702 } 1712 }
1703 1713
1704#if EV_PERIODIC_ENABLE 1714#if EV_PERIODIC_ENABLE
1705 if (periodiccnt) 1715 if (periodiccnt)
1706 { 1716 {
1707 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + backend_fudge; 1717 ev_tstamp to = ev_at (periodics [1]) - ev_rt_now + backend_fudge;
1708 if (waittime > to) waittime = to; 1718 if (waittime > to) waittime = to;
1709 } 1719 }
1710#endif 1720#endif
1711 1721
1712 if (expect_false (waittime < timeout_blocktime)) 1722 if (expect_false (waittime < timeout_blocktime))
1878ev_timer_start (EV_P_ ev_timer *w) 1888ev_timer_start (EV_P_ ev_timer *w)
1879{ 1889{
1880 if (expect_false (ev_is_active (w))) 1890 if (expect_false (ev_is_active (w)))
1881 return; 1891 return;
1882 1892
1883 ((WT)w)->at += mn_now; 1893 ev_at (w) += mn_now;
1884 1894
1885 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1895 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1886 1896
1887 ev_start (EV_A_ (W)w, ++timercnt); 1897 ev_start (EV_A_ (W)w, ++timercnt);
1888 array_needsize (WT, timers, timermax, timercnt, EMPTY2); 1898 array_needsize (WT, timers, timermax, timercnt + 1, EMPTY2);
1889 timers [timercnt - 1] = (WT)w; 1899 timers [timercnt] = (WT)w;
1890 upheap (timers, timercnt - 1); 1900 upheap (timers, timercnt);
1891 1901
1892 /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ 1902 /*assert (("internal timer heap corruption", timers [ev_active (w)] == w));*/
1893} 1903}
1894 1904
1895void noinline 1905void noinline
1896ev_timer_stop (EV_P_ ev_timer *w) 1906ev_timer_stop (EV_P_ ev_timer *w)
1897{ 1907{
1898 clear_pending (EV_A_ (W)w); 1908 clear_pending (EV_A_ (W)w);
1899 if (expect_false (!ev_is_active (w))) 1909 if (expect_false (!ev_is_active (w)))
1900 return; 1910 return;
1901 1911
1902 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == (WT)w));
1903
1904 { 1912 {
1905 int active = ((W)w)->active; 1913 int active = ev_active (w);
1906 1914
1915 assert (("internal timer heap corruption", timers [active] == (WT)w));
1916
1907 if (expect_true (--active < --timercnt)) 1917 if (expect_true (active < timercnt))
1908 { 1918 {
1909 timers [active] = timers [timercnt]; 1919 timers [active] = timers [timercnt];
1910 adjustheap (timers, timercnt, active); 1920 adjustheap (timers, timercnt, active);
1911 } 1921 }
1922
1923 --timercnt;
1912 } 1924 }
1913 1925
1914 ((WT)w)->at -= mn_now; 1926 ev_at (w) -= mn_now;
1915 1927
1916 ev_stop (EV_A_ (W)w); 1928 ev_stop (EV_A_ (W)w);
1917} 1929}
1918 1930
1919void noinline 1931void noinline
1921{ 1933{
1922 if (ev_is_active (w)) 1934 if (ev_is_active (w))
1923 { 1935 {
1924 if (w->repeat) 1936 if (w->repeat)
1925 { 1937 {
1926 ((WT)w)->at = mn_now + w->repeat; 1938 ev_at (w) = mn_now + w->repeat;
1927 adjustheap (timers, timercnt, ((W)w)->active - 1); 1939 adjustheap (timers, timercnt, ev_active (w));
1928 } 1940 }
1929 else 1941 else
1930 ev_timer_stop (EV_A_ w); 1942 ev_timer_stop (EV_A_ w);
1931 } 1943 }
1932 else if (w->repeat) 1944 else if (w->repeat)
1933 { 1945 {
1934 w->at = w->repeat; 1946 ev_at (w) = w->repeat;
1935 ev_timer_start (EV_A_ w); 1947 ev_timer_start (EV_A_ w);
1936 } 1948 }
1937} 1949}
1938 1950
1939#if EV_PERIODIC_ENABLE 1951#if EV_PERIODIC_ENABLE
1942{ 1954{
1943 if (expect_false (ev_is_active (w))) 1955 if (expect_false (ev_is_active (w)))
1944 return; 1956 return;
1945 1957
1946 if (w->reschedule_cb) 1958 if (w->reschedule_cb)
1947 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); 1959 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
1948 else if (w->interval) 1960 else if (w->interval)
1949 { 1961 {
1950 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); 1962 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 */ 1963 /* 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; 1964 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1953 } 1965 }
1954 else 1966 else
1955 ((WT)w)->at = w->offset; 1967 ev_at (w) = w->offset;
1956 1968
1957 ev_start (EV_A_ (W)w, ++periodiccnt); 1969 ev_start (EV_A_ (W)w, ++periodiccnt);
1958 array_needsize (WT, periodics, periodicmax, periodiccnt, EMPTY2); 1970 array_needsize (WT, periodics, periodicmax, periodiccnt + 1, EMPTY2);
1959 periodics [periodiccnt - 1] = (WT)w; 1971 periodics [periodiccnt] = (WT)w;
1960 upheap (periodics, periodiccnt - 1); 1972 upheap (periodics, periodiccnt);
1961 1973
1962 /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ 1974 /*assert (("internal periodic heap corruption", periodics [ev_active (w)] == w));*/
1963} 1975}
1964 1976
1965void noinline 1977void noinline
1966ev_periodic_stop (EV_P_ ev_periodic *w) 1978ev_periodic_stop (EV_P_ ev_periodic *w)
1967{ 1979{
1968 clear_pending (EV_A_ (W)w); 1980 clear_pending (EV_A_ (W)w);
1969 if (expect_false (!ev_is_active (w))) 1981 if (expect_false (!ev_is_active (w)))
1970 return; 1982 return;
1971 1983
1972 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == (WT)w));
1973
1974 { 1984 {
1975 int active = ((W)w)->active; 1985 int active = ev_active (w);
1976 1986
1987 assert (("internal periodic heap corruption", periodics [active] == (WT)w));
1988
1977 if (expect_true (--active < --periodiccnt)) 1989 if (expect_true (active < periodiccnt))
1978 { 1990 {
1979 periodics [active] = periodics [periodiccnt]; 1991 periodics [active] = periodics [periodiccnt];
1980 adjustheap (periodics, periodiccnt, active); 1992 adjustheap (periodics, periodiccnt, active);
1981 } 1993 }
1994
1995 --periodiccnt;
1982 } 1996 }
1983 1997
1984 ev_stop (EV_A_ (W)w); 1998 ev_stop (EV_A_ (W)w);
1985} 1999}
1986 2000
2102 if (w->wd < 0) 2116 if (w->wd < 0)
2103 { 2117 {
2104 ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */ 2118 ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */
2105 2119
2106 /* monitor some parent directory for speedup hints */ 2120 /* monitor some parent directory for speedup hints */
2121 /* note that exceeding the hardcoded limit is not a correctness issue, */
2122 /* but an efficiency issue only */
2107 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) 2123 if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096)
2108 { 2124 {
2109 char path [4096]; 2125 char path [4096];
2110 strcpy (path, w->path); 2126 strcpy (path, w->path);
2111 2127
2356 clear_pending (EV_A_ (W)w); 2372 clear_pending (EV_A_ (W)w);
2357 if (expect_false (!ev_is_active (w))) 2373 if (expect_false (!ev_is_active (w)))
2358 return; 2374 return;
2359 2375
2360 { 2376 {
2361 int active = ((W)w)->active; 2377 int active = ev_active (w);
2362 2378
2363 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; 2379 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]];
2364 ((W)idles [ABSPRI (w)][active - 1])->active = active; 2380 ev_active (idles [ABSPRI (w)][active - 1]) = active;
2365 2381
2366 ev_stop (EV_A_ (W)w); 2382 ev_stop (EV_A_ (W)w);
2367 --idleall; 2383 --idleall;
2368 } 2384 }
2369} 2385}
2386 clear_pending (EV_A_ (W)w); 2402 clear_pending (EV_A_ (W)w);
2387 if (expect_false (!ev_is_active (w))) 2403 if (expect_false (!ev_is_active (w)))
2388 return; 2404 return;
2389 2405
2390 { 2406 {
2391 int active = ((W)w)->active; 2407 int active = ev_active (w);
2408
2392 prepares [active - 1] = prepares [--preparecnt]; 2409 prepares [active - 1] = prepares [--preparecnt];
2393 ((W)prepares [active - 1])->active = active; 2410 ev_active (prepares [active - 1]) = active;
2394 } 2411 }
2395 2412
2396 ev_stop (EV_A_ (W)w); 2413 ev_stop (EV_A_ (W)w);
2397} 2414}
2398 2415
2413 clear_pending (EV_A_ (W)w); 2430 clear_pending (EV_A_ (W)w);
2414 if (expect_false (!ev_is_active (w))) 2431 if (expect_false (!ev_is_active (w)))
2415 return; 2432 return;
2416 2433
2417 { 2434 {
2418 int active = ((W)w)->active; 2435 int active = ev_active (w);
2436
2419 checks [active - 1] = checks [--checkcnt]; 2437 checks [active - 1] = checks [--checkcnt];
2420 ((W)checks [active - 1])->active = active; 2438 ev_active (checks [active - 1]) = active;
2421 } 2439 }
2422 2440
2423 ev_stop (EV_A_ (W)w); 2441 ev_stop (EV_A_ (W)w);
2424} 2442}
2425 2443
2521 clear_pending (EV_A_ (W)w); 2539 clear_pending (EV_A_ (W)w);
2522 if (expect_false (!ev_is_active (w))) 2540 if (expect_false (!ev_is_active (w)))
2523 return; 2541 return;
2524 2542
2525 { 2543 {
2526 int active = ((W)w)->active; 2544 int active = ev_active (w);
2545
2527 forks [active - 1] = forks [--forkcnt]; 2546 forks [active - 1] = forks [--forkcnt];
2528 ((W)forks [active - 1])->active = active; 2547 ev_active (forks [active - 1]) = active;
2529 } 2548 }
2530 2549
2531 ev_stop (EV_A_ (W)w); 2550 ev_stop (EV_A_ (W)w);
2532} 2551}
2533#endif 2552#endif
2552 clear_pending (EV_A_ (W)w); 2571 clear_pending (EV_A_ (W)w);
2553 if (expect_false (!ev_is_active (w))) 2572 if (expect_false (!ev_is_active (w)))
2554 return; 2573 return;
2555 2574
2556 { 2575 {
2557 int active = ((W)w)->active; 2576 int active = ev_active (w);
2577
2558 asyncs [active - 1] = asyncs [--asynccnt]; 2578 asyncs [active - 1] = asyncs [--asynccnt];
2559 ((W)asyncs [active - 1])->active = active; 2579 ev_active (asyncs [active - 1]) = active;
2560 } 2580 }
2561 2581
2562 ev_stop (EV_A_ (W)w); 2582 ev_stop (EV_A_ (W)w);
2563} 2583}
2564 2584

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines