… | |
… | |
325 | |
325 | |
326 | typedef ev_watcher *W; |
326 | typedef ev_watcher *W; |
327 | typedef ev_watcher_list *WL; |
327 | typedef ev_watcher_list *WL; |
328 | typedef ev_watcher_time *WT; |
328 | typedef 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 */ |
333 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
336 | static 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 | |
522 | int inline_size |
527 | int inline_size |
523 | array_nextsize (int elem, int cur, int cnt) |
528 | array_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; |
… | |
… | |
760 | void inline_speed |
765 | void inline_speed |
761 | upheap (WT *heap, int k) |
766 | upheap (WT *heap, int k) |
762 | { |
767 | { |
763 | WT w = heap [k]; |
768 | WT w = heap [k]; |
764 | |
769 | |
765 | while (k) |
770 | for (;;) |
766 | { |
771 | { |
767 | int p = (k - 1) >> 1; |
772 | int p = k >> 1; |
768 | |
773 | |
|
|
774 | /* maybe we could use a dummy element at heap [0]? */ |
769 | if (heap [p]->at <= w->at) |
775 | if (!p || heap [p]->at <= w->at) |
770 | break; |
776 | break; |
771 | |
777 | |
772 | heap [k] = heap [p]; |
778 | heap [k] = heap [p]; |
773 | ((W)heap [k])->active = k + 1; |
779 | ev_active (heap [k]) = k; |
774 | k = p; |
780 | k = p; |
775 | } |
781 | } |
776 | |
782 | |
777 | heap [k] = w; |
783 | heap [k] = w; |
778 | ((W)heap [k])->active = k + 1; |
784 | ev_active (heap [k]) = k; |
779 | } |
785 | } |
780 | |
786 | |
781 | /* away from the root */ |
787 | /* away from the root */ |
782 | void inline_speed |
788 | void inline_speed |
783 | downheap (WT *heap, int N, int k) |
789 | downheap (WT *heap, int N, int k) |
784 | { |
790 | { |
785 | WT w = heap [k]; |
791 | WT w = heap [k]; |
786 | |
792 | |
787 | for (;;) |
793 | for (;;) |
788 | { |
794 | { |
789 | int c = (k << 1) + 1; |
795 | int c = k << 1; |
790 | |
796 | |
791 | if (c >= N) |
797 | if (c > N) |
792 | break; |
798 | break; |
793 | |
799 | |
794 | c += c + 1 < N && heap [c]->at > heap [c + 1]->at |
800 | c += c < N && heap [c]->at > heap [c + 1]->at |
795 | ? 1 : 0; |
801 | ? 1 : 0; |
796 | |
802 | |
797 | if (w->at <= heap [c]->at) |
803 | if (w->at <= heap [c]->at) |
798 | break; |
804 | break; |
799 | |
805 | |
800 | heap [k] = heap [c]; |
806 | heap [k] = heap [c]; |
801 | ((W)heap [k])->active = k + 1; |
807 | ev_active (heap [k]) = k; |
802 | |
808 | |
803 | k = c; |
809 | k = c; |
804 | } |
810 | } |
805 | |
811 | |
806 | heap [k] = w; |
812 | heap [k] = w; |
807 | ((W)heap [k])->active = k + 1; |
813 | ev_active (heap [k]) = k; |
808 | } |
814 | } |
809 | |
815 | |
810 | void inline_size |
816 | void inline_size |
811 | adjustheap (WT *heap, int N, int k) |
817 | adjustheap (WT *heap, int N, int k) |
812 | { |
818 | { |
… | |
… | |
908 | pipecb (EV_P_ ev_io *iow, int revents) |
914 | pipecb (EV_P_ ev_io *iow, int revents) |
909 | { |
915 | { |
910 | #if EV_USE_EVENTFD |
916 | #if EV_USE_EVENTFD |
911 | if (evfd >= 0) |
917 | if (evfd >= 0) |
912 | { |
918 | { |
913 | uint64_t counter = 1; |
919 | uint64_t counter; |
914 | read (evfd, &counter, sizeof (uint64_t)); |
920 | read (evfd, &counter, sizeof (uint64_t)); |
915 | } |
921 | } |
916 | else |
922 | else |
917 | #endif |
923 | #endif |
918 | { |
924 | { |
… | |
… | |
1458 | } |
1464 | } |
1459 | |
1465 | |
1460 | void inline_size |
1466 | void inline_size |
1461 | timers_reify (EV_P) |
1467 | timers_reify (EV_P) |
1462 | { |
1468 | { |
1463 | while (timercnt && ((WT)timers [0])->at <= mn_now) |
1469 | while (timercnt && ev_at (timers [1]) <= mn_now) |
1464 | { |
1470 | { |
1465 | ev_timer *w = (ev_timer *)timers [0]; |
1471 | ev_timer *w = (ev_timer *)timers [1]; |
1466 | |
1472 | |
1467 | /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ |
1473 | /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ |
1468 | |
1474 | |
1469 | /* first reschedule or stop timer */ |
1475 | /* first reschedule or stop timer */ |
1470 | if (w->repeat) |
1476 | if (w->repeat) |
1471 | { |
1477 | { |
1472 | 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.)); |
1473 | |
1479 | |
1474 | ((WT)w)->at += w->repeat; |
1480 | ev_at (w) += w->repeat; |
1475 | if (((WT)w)->at < mn_now) |
1481 | if (ev_at (w) < mn_now) |
1476 | ((WT)w)->at = mn_now; |
1482 | ev_at (w) = mn_now; |
1477 | |
1483 | |
1478 | downheap (timers, timercnt, 0); |
1484 | downheap (timers, timercnt, 1); |
1479 | } |
1485 | } |
1480 | else |
1486 | else |
1481 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1487 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1482 | |
1488 | |
1483 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
1489 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
… | |
… | |
1486 | |
1492 | |
1487 | #if EV_PERIODIC_ENABLE |
1493 | #if EV_PERIODIC_ENABLE |
1488 | void inline_size |
1494 | void inline_size |
1489 | periodics_reify (EV_P) |
1495 | periodics_reify (EV_P) |
1490 | { |
1496 | { |
1491 | while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) |
1497 | while (periodiccnt && ev_at (periodics [1]) <= ev_rt_now) |
1492 | { |
1498 | { |
1493 | ev_periodic *w = (ev_periodic *)periodics [0]; |
1499 | ev_periodic *w = (ev_periodic *)periodics [1]; |
1494 | |
1500 | |
1495 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1501 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1496 | |
1502 | |
1497 | /* first reschedule or stop timer */ |
1503 | /* first reschedule or stop timer */ |
1498 | if (w->reschedule_cb) |
1504 | if (w->reschedule_cb) |
1499 | { |
1505 | { |
1500 | ((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); |
1501 | 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)); |
1502 | downheap (periodics, periodiccnt, 0); |
1508 | downheap (periodics, periodiccnt, 1); |
1503 | } |
1509 | } |
1504 | else if (w->interval) |
1510 | else if (w->interval) |
1505 | { |
1511 | { |
1506 | ((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; |
1507 | 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; |
1508 | 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)); |
1509 | downheap (periodics, periodiccnt, 0); |
1515 | downheap (periodics, periodiccnt, 1); |
1510 | } |
1516 | } |
1511 | else |
1517 | else |
1512 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1518 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1513 | |
1519 | |
1514 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
1520 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
… | |
… | |
1519 | periodics_reschedule (EV_P) |
1525 | periodics_reschedule (EV_P) |
1520 | { |
1526 | { |
1521 | int i; |
1527 | int i; |
1522 | |
1528 | |
1523 | /* adjust periodics after time jump */ |
1529 | /* adjust periodics after time jump */ |
1524 | for (i = 0; i < periodiccnt; ++i) |
1530 | for (i = 1; i <= periodiccnt; ++i) |
1525 | { |
1531 | { |
1526 | ev_periodic *w = (ev_periodic *)periodics [i]; |
1532 | ev_periodic *w = (ev_periodic *)periodics [i]; |
1527 | |
1533 | |
1528 | if (w->reschedule_cb) |
1534 | if (w->reschedule_cb) |
1529 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1535 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
1530 | else if (w->interval) |
1536 | else if (w->interval) |
1531 | ((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; |
1532 | } |
1538 | } |
1533 | |
1539 | |
1534 | /* now rebuild the heap */ |
1540 | /* now rebuild the heap */ |
1535 | for (i = periodiccnt >> 1; i--; ) |
1541 | for (i = periodiccnt >> 1; i--; ) |
1536 | downheap (periodics, periodiccnt, i); |
1542 | downheap (periodics, periodiccnt, i); |
… | |
… | |
1618 | { |
1624 | { |
1619 | #if EV_PERIODIC_ENABLE |
1625 | #if EV_PERIODIC_ENABLE |
1620 | periodics_reschedule (EV_A); |
1626 | periodics_reschedule (EV_A); |
1621 | #endif |
1627 | #endif |
1622 | /* 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 */ |
1623 | for (i = 0; i < timercnt; ++i) |
1629 | for (i = 1; i <= timercnt; ++i) |
1624 | ((WT)timers [i])->at += ev_rt_now - mn_now; |
1630 | ev_at (timers [i]) += ev_rt_now - mn_now; |
1625 | } |
1631 | } |
1626 | |
1632 | |
1627 | mn_now = ev_rt_now; |
1633 | mn_now = ev_rt_now; |
1628 | } |
1634 | } |
1629 | } |
1635 | } |
… | |
… | |
1699 | |
1705 | |
1700 | waittime = MAX_BLOCKTIME; |
1706 | waittime = MAX_BLOCKTIME; |
1701 | |
1707 | |
1702 | if (timercnt) |
1708 | if (timercnt) |
1703 | { |
1709 | { |
1704 | ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge; |
1710 | ev_tstamp to = ev_at (timers [1]) - mn_now + backend_fudge; |
1705 | if (waittime > to) waittime = to; |
1711 | if (waittime > to) waittime = to; |
1706 | } |
1712 | } |
1707 | |
1713 | |
1708 | #if EV_PERIODIC_ENABLE |
1714 | #if EV_PERIODIC_ENABLE |
1709 | if (periodiccnt) |
1715 | if (periodiccnt) |
1710 | { |
1716 | { |
1711 | 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; |
1712 | if (waittime > to) waittime = to; |
1718 | if (waittime > to) waittime = to; |
1713 | } |
1719 | } |
1714 | #endif |
1720 | #endif |
1715 | |
1721 | |
1716 | if (expect_false (waittime < timeout_blocktime)) |
1722 | if (expect_false (waittime < timeout_blocktime)) |
… | |
… | |
1882 | ev_timer_start (EV_P_ ev_timer *w) |
1888 | ev_timer_start (EV_P_ ev_timer *w) |
1883 | { |
1889 | { |
1884 | if (expect_false (ev_is_active (w))) |
1890 | if (expect_false (ev_is_active (w))) |
1885 | return; |
1891 | return; |
1886 | |
1892 | |
1887 | ((WT)w)->at += mn_now; |
1893 | ev_at (w) += mn_now; |
1888 | |
1894 | |
1889 | 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.)); |
1890 | |
1896 | |
1891 | ev_start (EV_A_ (W)w, ++timercnt); |
1897 | ev_start (EV_A_ (W)w, ++timercnt); |
1892 | array_needsize (WT, timers, timermax, timercnt, EMPTY2); |
1898 | array_needsize (WT, timers, timermax, timercnt + 1, EMPTY2); |
1893 | timers [timercnt - 1] = (WT)w; |
1899 | timers [timercnt] = (WT)w; |
1894 | upheap (timers, timercnt - 1); |
1900 | upheap (timers, timercnt); |
1895 | |
1901 | |
1896 | /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ |
1902 | /*assert (("internal timer heap corruption", timers [ev_active (w)] == w));*/ |
1897 | } |
1903 | } |
1898 | |
1904 | |
1899 | void noinline |
1905 | void noinline |
1900 | ev_timer_stop (EV_P_ ev_timer *w) |
1906 | ev_timer_stop (EV_P_ ev_timer *w) |
1901 | { |
1907 | { |
1902 | clear_pending (EV_A_ (W)w); |
1908 | clear_pending (EV_A_ (W)w); |
1903 | if (expect_false (!ev_is_active (w))) |
1909 | if (expect_false (!ev_is_active (w))) |
1904 | return; |
1910 | return; |
1905 | |
1911 | |
1906 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == (WT)w)); |
|
|
1907 | |
|
|
1908 | { |
1912 | { |
1909 | int active = ((W)w)->active; |
1913 | int active = ev_active (w); |
1910 | |
1914 | |
|
|
1915 | assert (("internal timer heap corruption", timers [active] == (WT)w)); |
|
|
1916 | |
1911 | if (expect_true (--active < --timercnt)) |
1917 | if (expect_true (active < timercnt)) |
1912 | { |
1918 | { |
1913 | timers [active] = timers [timercnt]; |
1919 | timers [active] = timers [timercnt]; |
1914 | adjustheap (timers, timercnt, active); |
1920 | adjustheap (timers, timercnt, active); |
1915 | } |
1921 | } |
|
|
1922 | |
|
|
1923 | --timercnt; |
1916 | } |
1924 | } |
1917 | |
1925 | |
1918 | ((WT)w)->at -= mn_now; |
1926 | ev_at (w) -= mn_now; |
1919 | |
1927 | |
1920 | ev_stop (EV_A_ (W)w); |
1928 | ev_stop (EV_A_ (W)w); |
1921 | } |
1929 | } |
1922 | |
1930 | |
1923 | void noinline |
1931 | void noinline |
… | |
… | |
1925 | { |
1933 | { |
1926 | if (ev_is_active (w)) |
1934 | if (ev_is_active (w)) |
1927 | { |
1935 | { |
1928 | if (w->repeat) |
1936 | if (w->repeat) |
1929 | { |
1937 | { |
1930 | ((WT)w)->at = mn_now + w->repeat; |
1938 | ev_at (w) = mn_now + w->repeat; |
1931 | adjustheap (timers, timercnt, ((W)w)->active - 1); |
1939 | adjustheap (timers, timercnt, ev_active (w)); |
1932 | } |
1940 | } |
1933 | else |
1941 | else |
1934 | ev_timer_stop (EV_A_ w); |
1942 | ev_timer_stop (EV_A_ w); |
1935 | } |
1943 | } |
1936 | else if (w->repeat) |
1944 | else if (w->repeat) |
1937 | { |
1945 | { |
1938 | w->at = w->repeat; |
1946 | ev_at (w) = w->repeat; |
1939 | ev_timer_start (EV_A_ w); |
1947 | ev_timer_start (EV_A_ w); |
1940 | } |
1948 | } |
1941 | } |
1949 | } |
1942 | |
1950 | |
1943 | #if EV_PERIODIC_ENABLE |
1951 | #if EV_PERIODIC_ENABLE |
… | |
… | |
1946 | { |
1954 | { |
1947 | if (expect_false (ev_is_active (w))) |
1955 | if (expect_false (ev_is_active (w))) |
1948 | return; |
1956 | return; |
1949 | |
1957 | |
1950 | if (w->reschedule_cb) |
1958 | if (w->reschedule_cb) |
1951 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1959 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
1952 | else if (w->interval) |
1960 | else if (w->interval) |
1953 | { |
1961 | { |
1954 | 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.)); |
1955 | /* 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 */ |
1956 | ((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; |
1957 | } |
1965 | } |
1958 | else |
1966 | else |
1959 | ((WT)w)->at = w->offset; |
1967 | ev_at (w) = w->offset; |
1960 | |
1968 | |
1961 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1969 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1962 | array_needsize (WT, periodics, periodicmax, periodiccnt, EMPTY2); |
1970 | array_needsize (WT, periodics, periodicmax, periodiccnt + 1, EMPTY2); |
1963 | periodics [periodiccnt - 1] = (WT)w; |
1971 | periodics [periodiccnt] = (WT)w; |
1964 | upheap (periodics, periodiccnt - 1); |
1972 | upheap (periodics, periodiccnt); |
1965 | |
1973 | |
1966 | /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ |
1974 | /*assert (("internal periodic heap corruption", periodics [ev_active (w)] == w));*/ |
1967 | } |
1975 | } |
1968 | |
1976 | |
1969 | void noinline |
1977 | void noinline |
1970 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1978 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1971 | { |
1979 | { |
1972 | clear_pending (EV_A_ (W)w); |
1980 | clear_pending (EV_A_ (W)w); |
1973 | if (expect_false (!ev_is_active (w))) |
1981 | if (expect_false (!ev_is_active (w))) |
1974 | return; |
1982 | return; |
1975 | |
1983 | |
1976 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == (WT)w)); |
|
|
1977 | |
|
|
1978 | { |
1984 | { |
1979 | int active = ((W)w)->active; |
1985 | int active = ev_active (w); |
1980 | |
1986 | |
|
|
1987 | assert (("internal periodic heap corruption", periodics [active] == (WT)w)); |
|
|
1988 | |
1981 | if (expect_true (--active < --periodiccnt)) |
1989 | if (expect_true (active < periodiccnt)) |
1982 | { |
1990 | { |
1983 | periodics [active] = periodics [periodiccnt]; |
1991 | periodics [active] = periodics [periodiccnt]; |
1984 | adjustheap (periodics, periodiccnt, active); |
1992 | adjustheap (periodics, periodiccnt, active); |
1985 | } |
1993 | } |
|
|
1994 | |
|
|
1995 | --periodiccnt; |
1986 | } |
1996 | } |
1987 | |
1997 | |
1988 | ev_stop (EV_A_ (W)w); |
1998 | ev_stop (EV_A_ (W)w); |
1989 | } |
1999 | } |
1990 | |
2000 | |
… | |
… | |
2106 | if (w->wd < 0) |
2116 | if (w->wd < 0) |
2107 | { |
2117 | { |
2108 | 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 */ |
2109 | |
2119 | |
2110 | /* 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 */ |
2111 | if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) |
2123 | if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) |
2112 | { |
2124 | { |
2113 | char path [4096]; |
2125 | char path [4096]; |
2114 | strcpy (path, w->path); |
2126 | strcpy (path, w->path); |
2115 | |
2127 | |
… | |
… | |
2360 | clear_pending (EV_A_ (W)w); |
2372 | clear_pending (EV_A_ (W)w); |
2361 | if (expect_false (!ev_is_active (w))) |
2373 | if (expect_false (!ev_is_active (w))) |
2362 | return; |
2374 | return; |
2363 | |
2375 | |
2364 | { |
2376 | { |
2365 | int active = ((W)w)->active; |
2377 | int active = ev_active (w); |
2366 | |
2378 | |
2367 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
2379 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
2368 | ((W)idles [ABSPRI (w)][active - 1])->active = active; |
2380 | ev_active (idles [ABSPRI (w)][active - 1]) = active; |
2369 | |
2381 | |
2370 | ev_stop (EV_A_ (W)w); |
2382 | ev_stop (EV_A_ (W)w); |
2371 | --idleall; |
2383 | --idleall; |
2372 | } |
2384 | } |
2373 | } |
2385 | } |
… | |
… | |
2390 | clear_pending (EV_A_ (W)w); |
2402 | clear_pending (EV_A_ (W)w); |
2391 | if (expect_false (!ev_is_active (w))) |
2403 | if (expect_false (!ev_is_active (w))) |
2392 | return; |
2404 | return; |
2393 | |
2405 | |
2394 | { |
2406 | { |
2395 | int active = ((W)w)->active; |
2407 | int active = ev_active (w); |
|
|
2408 | |
2396 | prepares [active - 1] = prepares [--preparecnt]; |
2409 | prepares [active - 1] = prepares [--preparecnt]; |
2397 | ((W)prepares [active - 1])->active = active; |
2410 | ev_active (prepares [active - 1]) = active; |
2398 | } |
2411 | } |
2399 | |
2412 | |
2400 | ev_stop (EV_A_ (W)w); |
2413 | ev_stop (EV_A_ (W)w); |
2401 | } |
2414 | } |
2402 | |
2415 | |
… | |
… | |
2417 | clear_pending (EV_A_ (W)w); |
2430 | clear_pending (EV_A_ (W)w); |
2418 | if (expect_false (!ev_is_active (w))) |
2431 | if (expect_false (!ev_is_active (w))) |
2419 | return; |
2432 | return; |
2420 | |
2433 | |
2421 | { |
2434 | { |
2422 | int active = ((W)w)->active; |
2435 | int active = ev_active (w); |
|
|
2436 | |
2423 | checks [active - 1] = checks [--checkcnt]; |
2437 | checks [active - 1] = checks [--checkcnt]; |
2424 | ((W)checks [active - 1])->active = active; |
2438 | ev_active (checks [active - 1]) = active; |
2425 | } |
2439 | } |
2426 | |
2440 | |
2427 | ev_stop (EV_A_ (W)w); |
2441 | ev_stop (EV_A_ (W)w); |
2428 | } |
2442 | } |
2429 | |
2443 | |
… | |
… | |
2525 | clear_pending (EV_A_ (W)w); |
2539 | clear_pending (EV_A_ (W)w); |
2526 | if (expect_false (!ev_is_active (w))) |
2540 | if (expect_false (!ev_is_active (w))) |
2527 | return; |
2541 | return; |
2528 | |
2542 | |
2529 | { |
2543 | { |
2530 | int active = ((W)w)->active; |
2544 | int active = ev_active (w); |
|
|
2545 | |
2531 | forks [active - 1] = forks [--forkcnt]; |
2546 | forks [active - 1] = forks [--forkcnt]; |
2532 | ((W)forks [active - 1])->active = active; |
2547 | ev_active (forks [active - 1]) = active; |
2533 | } |
2548 | } |
2534 | |
2549 | |
2535 | ev_stop (EV_A_ (W)w); |
2550 | ev_stop (EV_A_ (W)w); |
2536 | } |
2551 | } |
2537 | #endif |
2552 | #endif |
… | |
… | |
2556 | clear_pending (EV_A_ (W)w); |
2571 | clear_pending (EV_A_ (W)w); |
2557 | if (expect_false (!ev_is_active (w))) |
2572 | if (expect_false (!ev_is_active (w))) |
2558 | return; |
2573 | return; |
2559 | |
2574 | |
2560 | { |
2575 | { |
2561 | int active = ((W)w)->active; |
2576 | int active = ev_active (w); |
|
|
2577 | |
2562 | asyncs [active - 1] = asyncs [--asynccnt]; |
2578 | asyncs [active - 1] = asyncs [--asynccnt]; |
2563 | ((W)asyncs [active - 1])->active = active; |
2579 | ev_active (asyncs [active - 1]) = active; |
2564 | } |
2580 | } |
2565 | |
2581 | |
2566 | ev_stop (EV_A_ (W)w); |
2582 | ev_stop (EV_A_ (W)w); |
2567 | } |
2583 | } |
2568 | |
2584 | |