… | |
… | |
235 | # else |
235 | # else |
236 | # define EV_USE_EVENTFD 0 |
236 | # define EV_USE_EVENTFD 0 |
237 | # endif |
237 | # endif |
238 | #endif |
238 | #endif |
239 | |
239 | |
|
|
240 | #if 0 /* debugging */ |
|
|
241 | # define EV_VERIFY 1 |
|
|
242 | # define EV_USE_4HEAP 1 |
|
|
243 | # define EV_HEAP_CACHE_AT 1 |
|
|
244 | #endif |
|
|
245 | |
240 | #ifndef EV_USE_4HEAP |
246 | #ifndef EV_USE_4HEAP |
241 | # define EV_USE_4HEAP !EV_MINIMAL |
247 | # define EV_USE_4HEAP !EV_MINIMAL |
242 | #endif |
248 | #endif |
243 | |
249 | |
244 | #ifndef EV_HEAP_CACHE_AT |
250 | #ifndef EV_HEAP_CACHE_AT |
… | |
… | |
287 | } |
293 | } |
288 | # endif |
294 | # endif |
289 | #endif |
295 | #endif |
290 | |
296 | |
291 | /**/ |
297 | /**/ |
|
|
298 | |
|
|
299 | /* EV_VERIFY: enable internal consistency checks |
|
|
300 | * undefined or zero: no verification done or available |
|
|
301 | * 1 or higher: ev_loop_verify function available |
|
|
302 | * 2 or higher: ev_loop_verify is called frequently |
|
|
303 | */ |
|
|
304 | #if EV_VERIFY >= 1 |
|
|
305 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
|
|
306 | #else |
|
|
307 | # define EV_FREQUENT_CHECK do { } while (0) |
|
|
308 | #endif |
292 | |
309 | |
293 | /* |
310 | /* |
294 | * This is used to avoid floating point rounding problems. |
311 | * This is used to avoid floating point rounding problems. |
295 | * It is added to ev_rt_now when scheduling periodics |
312 | * It is added to ev_rt_now when scheduling periodics |
296 | * to ensure progress, time-wise, even when rounding |
313 | * to ensure progress, time-wise, even when rounding |
… | |
… | |
444 | typedef struct { |
461 | typedef struct { |
445 | ev_tstamp at; |
462 | ev_tstamp at; |
446 | WT w; |
463 | WT w; |
447 | } ANHE; |
464 | } ANHE; |
448 | |
465 | |
449 | #define ANHE_w(he) (he).w /* access watcher, read-write */ |
466 | #define ANHE_w(he) (he).w /* access watcher, read-write */ |
450 | #define ANHE_at(he) (he).at /* access cached at, read-only */ |
467 | #define ANHE_at(he) (he).at /* access cached at, read-only */ |
451 | #define ANHE_at_set(he) (he).at = (he).w->at /* update at from watcher */ |
468 | #define ANHE_at_cache(he) (he).at = (he).w->at /* update at from watcher */ |
452 | #else |
469 | #else |
453 | typedef WT ANHE; |
470 | typedef WT ANHE; |
454 | |
471 | |
455 | #define ANHE_w(he) (he) |
472 | #define ANHE_w(he) (he) |
456 | #define ANHE_at(he) (he)->at |
473 | #define ANHE_at(he) (he)->at |
457 | #define ANHE_at_set(he) |
474 | #define ANHE_at_cache(he) |
458 | #endif |
475 | #endif |
459 | |
476 | |
460 | #if EV_MULTIPLICITY |
477 | #if EV_MULTIPLICITY |
461 | |
478 | |
462 | struct ev_loop |
479 | struct ev_loop |
… | |
… | |
803 | #if EV_USE_4HEAP |
820 | #if EV_USE_4HEAP |
804 | |
821 | |
805 | #define DHEAP 4 |
822 | #define DHEAP 4 |
806 | #define HEAP0 (DHEAP - 1) /* index of first element in heap */ |
823 | #define HEAP0 (DHEAP - 1) /* index of first element in heap */ |
807 | #define HPARENT(k) ((((k) - HEAP0 - 1) / DHEAP) + HEAP0) |
824 | #define HPARENT(k) ((((k) - HEAP0 - 1) / DHEAP) + HEAP0) |
808 | |
825 | #define UPHEAP_DONE(p,k) ((p) == (k)) |
809 | /* towards the root */ |
|
|
810 | void inline_speed |
|
|
811 | upheap (ANHE *heap, int k) |
|
|
812 | { |
|
|
813 | ANHE he = heap [k]; |
|
|
814 | |
|
|
815 | for (;;) |
|
|
816 | { |
|
|
817 | int p = HPARENT (k); |
|
|
818 | |
|
|
819 | if (p == k || ANHE_at (heap [p]) <= ANHE_at (he)) |
|
|
820 | break; |
|
|
821 | |
|
|
822 | heap [k] = heap [p]; |
|
|
823 | ev_active (ANHE_w (heap [k])) = k; |
|
|
824 | k = p; |
|
|
825 | } |
|
|
826 | |
|
|
827 | heap [k] = he; |
|
|
828 | ev_active (ANHE_w (he)) = k; |
|
|
829 | } |
|
|
830 | |
826 | |
831 | /* away from the root */ |
827 | /* away from the root */ |
832 | void inline_speed |
828 | void inline_speed |
833 | downheap (ANHE *heap, int N, int k) |
829 | downheap (ANHE *heap, int N, int k) |
834 | { |
830 | { |
… | |
… | |
837 | |
833 | |
838 | for (;;) |
834 | for (;;) |
839 | { |
835 | { |
840 | ev_tstamp minat; |
836 | ev_tstamp minat; |
841 | ANHE *minpos; |
837 | ANHE *minpos; |
842 | ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0; |
838 | ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0 + 1; |
843 | |
839 | |
844 | // find minimum child |
840 | /* find minimum child */ |
845 | if (expect_true (pos + DHEAP - 1 < E)) |
841 | if (expect_true (pos + DHEAP - 1 < E)) |
846 | { |
842 | { |
847 | /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
843 | /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
848 | if ( ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
844 | if ( ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
849 | if ( ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos)); |
845 | if ( ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos)); |
… | |
… | |
870 | |
866 | |
871 | heap [k] = he; |
867 | heap [k] = he; |
872 | ev_active (ANHE_w (he)) = k; |
868 | ev_active (ANHE_w (he)) = k; |
873 | } |
869 | } |
874 | |
870 | |
875 | #else // 4HEAP |
871 | #else /* 4HEAP */ |
876 | |
872 | |
877 | #define HEAP0 1 |
873 | #define HEAP0 1 |
878 | #define HPARENT(k) ((k) >> 1) |
874 | #define HPARENT(k) ((k) >> 1) |
879 | |
875 | #define UPHEAP_DONE(p,k) (!(p)) |
880 | /* towards the root */ |
|
|
881 | void inline_speed |
|
|
882 | upheap (ANHE *heap, int k) |
|
|
883 | { |
|
|
884 | ANHE he = heap [k]; |
|
|
885 | |
|
|
886 | for (;;) |
|
|
887 | { |
|
|
888 | int p = HPARENT (k); |
|
|
889 | |
|
|
890 | /* maybe we could use a dummy element at heap [0]? */ |
|
|
891 | if (!p || ANHE_at (heap [p]) <= ANHE_at (he)) |
|
|
892 | break; |
|
|
893 | |
|
|
894 | heap [k] = heap [p]; |
|
|
895 | ev_active (ANHE_w (heap [k])) = k; |
|
|
896 | k = p; |
|
|
897 | } |
|
|
898 | |
|
|
899 | heap [k] = he; |
|
|
900 | ev_active (ANHE_w (heap [k])) = k; |
|
|
901 | } |
|
|
902 | |
876 | |
903 | /* away from the root */ |
877 | /* away from the root */ |
904 | void inline_speed |
878 | void inline_speed |
905 | downheap (ANHE *heap, int N, int k) |
879 | downheap (ANHE *heap, int N, int k) |
906 | { |
880 | { |
… | |
… | |
908 | |
882 | |
909 | for (;;) |
883 | for (;;) |
910 | { |
884 | { |
911 | int c = k << 1; |
885 | int c = k << 1; |
912 | |
886 | |
913 | if (c > N) |
887 | if (c > N + HEAP0 - 1) |
914 | break; |
888 | break; |
915 | |
889 | |
916 | c += c + 1 < N && ANHE_at (heap [c]) > ANHE_at (heap [c + 1]) |
890 | c += c + 1 < N + HEAP0 && ANHE_at (heap [c]) > ANHE_at (heap [c + 1]) |
917 | ? 1 : 0; |
891 | ? 1 : 0; |
918 | |
892 | |
919 | if (ANHE_at (he) <= ANHE_at (heap [c])) |
893 | if (ANHE_at (he) <= ANHE_at (heap [c])) |
920 | break; |
894 | break; |
921 | |
895 | |
… | |
… | |
928 | heap [k] = he; |
902 | heap [k] = he; |
929 | ev_active (ANHE_w (he)) = k; |
903 | ev_active (ANHE_w (he)) = k; |
930 | } |
904 | } |
931 | #endif |
905 | #endif |
932 | |
906 | |
|
|
907 | /* towards the root */ |
|
|
908 | void inline_speed |
|
|
909 | upheap (ANHE *heap, int k) |
|
|
910 | { |
|
|
911 | ANHE he = heap [k]; |
|
|
912 | |
|
|
913 | for (;;) |
|
|
914 | { |
|
|
915 | int p = HPARENT (k); |
|
|
916 | |
|
|
917 | if (UPHEAP_DONE (p, k) || ANHE_at (heap [p]) <= ANHE_at (he)) |
|
|
918 | break; |
|
|
919 | |
|
|
920 | heap [k] = heap [p]; |
|
|
921 | ev_active (ANHE_w (heap [k])) = k; |
|
|
922 | k = p; |
|
|
923 | } |
|
|
924 | |
|
|
925 | heap [k] = he; |
|
|
926 | ev_active (ANHE_w (he)) = k; |
|
|
927 | } |
|
|
928 | |
933 | void inline_size |
929 | void inline_size |
934 | adjustheap (ANHE *heap, int N, int k) |
930 | adjustheap (ANHE *heap, int N, int k) |
935 | { |
931 | { |
936 | if (k > HEAP0 && ANHE_at (heap [HPARENT (k)]) >= ANHE_at (heap [k])) |
932 | if (k > HEAP0 && ANHE_at (heap [HPARENT (k)]) >= ANHE_at (heap [k])) |
937 | upheap (heap, k); |
933 | upheap (heap, k); |
938 | else |
934 | else |
939 | downheap (heap, N, k); |
935 | downheap (heap, N, k); |
940 | } |
936 | } |
|
|
937 | |
|
|
938 | /* rebuild the heap: this function is used only once and executed rarely */ |
|
|
939 | void inline_size |
|
|
940 | reheap (ANHE *heap, int N) |
|
|
941 | { |
|
|
942 | int i; |
|
|
943 | /* we don't use floyds algorithm, upheap is simpler and is more cache-efficient */ |
|
|
944 | /* also, this is easy to implement and correct for both 2-heaps and 4-heaps */ |
|
|
945 | for (i = 0; i < N; ++i) |
|
|
946 | upheap (heap, i + HEAP0); |
|
|
947 | } |
|
|
948 | |
|
|
949 | #if EV_VERIFY |
|
|
950 | static void |
|
|
951 | checkheap (ANHE *heap, int N) |
|
|
952 | { |
|
|
953 | int i; |
|
|
954 | |
|
|
955 | for (i = HEAP0; i < N + HEAP0; ++i) |
|
|
956 | { |
|
|
957 | assert (("active index mismatch in heap", ev_active (ANHE_w (heap [i])) == i)); |
|
|
958 | assert (("heap condition violated", i == HEAP0 || ANHE_at (heap [HPARENT (i)]) <= ANHE_at (heap [i]))); |
|
|
959 | assert (("heap at cache mismatch", ANHE_at (heap [i]) == ev_at (ANHE_w (heap [i])))); |
|
|
960 | } |
|
|
961 | } |
|
|
962 | #endif |
941 | |
963 | |
942 | /*****************************************************************************/ |
964 | /*****************************************************************************/ |
943 | |
965 | |
944 | typedef struct |
966 | typedef struct |
945 | { |
967 | { |
… | |
… | |
1489 | void |
1511 | void |
1490 | ev_loop_fork (EV_P) |
1512 | ev_loop_fork (EV_P) |
1491 | { |
1513 | { |
1492 | postfork = 1; /* must be in line with ev_default_fork */ |
1514 | postfork = 1; /* must be in line with ev_default_fork */ |
1493 | } |
1515 | } |
|
|
1516 | |
|
|
1517 | #if EV_VERIFY |
|
|
1518 | static void |
|
|
1519 | array_check (W **ws, int cnt) |
|
|
1520 | { |
|
|
1521 | while (cnt--) |
|
|
1522 | assert (("active index mismatch", ev_active (ws [cnt]) == cnt + 1)); |
|
|
1523 | } |
|
|
1524 | |
|
|
1525 | static void |
|
|
1526 | ev_loop_verify (EV_P) |
|
|
1527 | { |
|
|
1528 | int i; |
|
|
1529 | |
|
|
1530 | checkheap (timers, timercnt); |
|
|
1531 | #if EV_PERIODIC_ENABLE |
|
|
1532 | checkheap (periodics, periodiccnt); |
|
|
1533 | #endif |
|
|
1534 | |
|
|
1535 | #if EV_IDLE_ENABLE |
|
|
1536 | for (i = NUMPRI; i--; ) |
|
|
1537 | array_check ((W **)idles [i], idlecnt [i]); |
|
|
1538 | #endif |
|
|
1539 | #if EV_FORK_ENABLE |
|
|
1540 | array_check ((W **)forks, forkcnt); |
|
|
1541 | #endif |
|
|
1542 | array_check ((W **)prepares, preparecnt); |
|
|
1543 | array_check ((W **)checks, checkcnt); |
|
|
1544 | #if EV_ASYNC_ENABLE |
|
|
1545 | array_check ((W **)asyncs, asynccnt); |
|
|
1546 | #endif |
|
|
1547 | } |
|
|
1548 | #endif |
|
|
1549 | |
1494 | #endif |
1550 | #endif |
1495 | |
1551 | |
1496 | #if EV_MULTIPLICITY |
1552 | #if EV_MULTIPLICITY |
1497 | struct ev_loop * |
1553 | struct ev_loop * |
1498 | ev_default_loop_init (unsigned int flags) |
1554 | ev_default_loop_init (unsigned int flags) |
… | |
… | |
1564 | void inline_speed |
1620 | void inline_speed |
1565 | call_pending (EV_P) |
1621 | call_pending (EV_P) |
1566 | { |
1622 | { |
1567 | int pri; |
1623 | int pri; |
1568 | |
1624 | |
|
|
1625 | EV_FREQUENT_CHECK; |
|
|
1626 | |
1569 | for (pri = NUMPRI; pri--; ) |
1627 | for (pri = NUMPRI; pri--; ) |
1570 | while (pendingcnt [pri]) |
1628 | while (pendingcnt [pri]) |
1571 | { |
1629 | { |
1572 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
1630 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
1573 | |
1631 | |
… | |
… | |
1577 | |
1635 | |
1578 | p->w->pending = 0; |
1636 | p->w->pending = 0; |
1579 | EV_CB_INVOKE (p->w, p->events); |
1637 | EV_CB_INVOKE (p->w, p->events); |
1580 | } |
1638 | } |
1581 | } |
1639 | } |
|
|
1640 | |
|
|
1641 | EV_FREQUENT_CHECK; |
1582 | } |
1642 | } |
1583 | |
1643 | |
1584 | #if EV_IDLE_ENABLE |
1644 | #if EV_IDLE_ENABLE |
1585 | void inline_size |
1645 | void inline_size |
1586 | idle_reify (EV_P) |
1646 | idle_reify (EV_P) |
… | |
… | |
1605 | #endif |
1665 | #endif |
1606 | |
1666 | |
1607 | void inline_size |
1667 | void inline_size |
1608 | timers_reify (EV_P) |
1668 | timers_reify (EV_P) |
1609 | { |
1669 | { |
|
|
1670 | EV_FREQUENT_CHECK; |
|
|
1671 | |
1610 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now) |
1672 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now) |
1611 | { |
1673 | { |
1612 | ev_timer *w = (ev_timer *)ANHE_w (timers [HEAP0]); |
1674 | ev_timer *w = (ev_timer *)ANHE_w (timers [HEAP0]); |
1613 | |
1675 | |
1614 | /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ |
1676 | /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ |
… | |
… | |
1620 | if (ev_at (w) < mn_now) |
1682 | if (ev_at (w) < mn_now) |
1621 | ev_at (w) = mn_now; |
1683 | ev_at (w) = mn_now; |
1622 | |
1684 | |
1623 | assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); |
1685 | assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); |
1624 | |
1686 | |
1625 | ANHE_at_set (timers [HEAP0]); |
1687 | ANHE_at_cache (timers [HEAP0]); |
1626 | downheap (timers, timercnt, HEAP0); |
1688 | downheap (timers, timercnt, HEAP0); |
1627 | } |
1689 | } |
1628 | else |
1690 | else |
1629 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1691 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1630 | |
1692 | |
|
|
1693 | EV_FREQUENT_CHECK; |
1631 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
1694 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
1632 | } |
1695 | } |
1633 | } |
1696 | } |
1634 | |
1697 | |
1635 | #if EV_PERIODIC_ENABLE |
1698 | #if EV_PERIODIC_ENABLE |
1636 | void inline_size |
1699 | void inline_size |
1637 | periodics_reify (EV_P) |
1700 | periodics_reify (EV_P) |
1638 | { |
1701 | { |
|
|
1702 | EV_FREQUENT_CHECK; |
1639 | while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) |
1703 | while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) |
1640 | { |
1704 | { |
1641 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); |
1705 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); |
1642 | |
1706 | |
1643 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1707 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
… | |
… | |
1647 | { |
1711 | { |
1648 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
1712 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
1649 | |
1713 | |
1650 | assert (("ev_periodic reschedule callback returned time in the past", ev_at (w) >= ev_rt_now)); |
1714 | assert (("ev_periodic reschedule callback returned time in the past", ev_at (w) >= ev_rt_now)); |
1651 | |
1715 | |
1652 | ANHE_at_set (periodics [HEAP0]); |
1716 | ANHE_at_cache (periodics [HEAP0]); |
1653 | downheap (periodics, periodiccnt, HEAP0); |
1717 | downheap (periodics, periodiccnt, HEAP0); |
|
|
1718 | EV_FREQUENT_CHECK; |
1654 | } |
1719 | } |
1655 | else if (w->interval) |
1720 | else if (w->interval) |
1656 | { |
1721 | { |
1657 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1722 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1658 | /* if next trigger time is not sufficiently in the future, put it there */ |
1723 | /* if next trigger time is not sufficiently in the future, put it there */ |
… | |
… | |
1666 | /* has effectively asked to get triggered more often than possible */ |
1731 | /* has effectively asked to get triggered more often than possible */ |
1667 | if (ev_at (w) < ev_rt_now) |
1732 | if (ev_at (w) < ev_rt_now) |
1668 | ev_at (w) = ev_rt_now; |
1733 | ev_at (w) = ev_rt_now; |
1669 | } |
1734 | } |
1670 | |
1735 | |
1671 | ANHE_at_set (periodics [HEAP0]); |
1736 | ANHE_at_cache (periodics [HEAP0]); |
1672 | downheap (periodics, periodiccnt, HEAP0); |
1737 | downheap (periodics, periodiccnt, HEAP0); |
1673 | } |
1738 | } |
1674 | else |
1739 | else |
1675 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1740 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1676 | |
1741 | |
|
|
1742 | EV_FREQUENT_CHECK; |
1677 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
1743 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
1678 | } |
1744 | } |
1679 | } |
1745 | } |
1680 | |
1746 | |
1681 | static void noinline |
1747 | static void noinline |
… | |
… | |
1691 | if (w->reschedule_cb) |
1757 | if (w->reschedule_cb) |
1692 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
1758 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
1693 | else if (w->interval) |
1759 | else if (w->interval) |
1694 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1760 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1695 | |
1761 | |
1696 | ANHE_at_set (periodics [i]); |
1762 | ANHE_at_cache (periodics [i]); |
1697 | } |
1763 | } |
1698 | |
1764 | |
1699 | /* we don't use floyds algorithm, uphead is simpler and is more cache-efficient */ |
1765 | reheap (periodics, periodiccnt); |
1700 | /* also, this is easy and corretc for both 2-heaps and 4-heaps */ |
|
|
1701 | for (i = 0; i < periodiccnt; ++i) |
|
|
1702 | upheap (periodics, i + HEAP0); |
|
|
1703 | } |
1766 | } |
1704 | #endif |
1767 | #endif |
1705 | |
1768 | |
1706 | void inline_speed |
1769 | void inline_speed |
1707 | time_update (EV_P_ ev_tstamp max_block) |
1770 | time_update (EV_P_ ev_tstamp max_block) |
… | |
… | |
1765 | /* adjust timers. this is easy, as the offset is the same for all of them */ |
1828 | /* adjust timers. this is easy, as the offset is the same for all of them */ |
1766 | for (i = 0; i < timercnt; ++i) |
1829 | for (i = 0; i < timercnt; ++i) |
1767 | { |
1830 | { |
1768 | ANHE *he = timers + i + HEAP0; |
1831 | ANHE *he = timers + i + HEAP0; |
1769 | ANHE_w (*he)->at += ev_rt_now - mn_now; |
1832 | ANHE_w (*he)->at += ev_rt_now - mn_now; |
1770 | ANHE_at_set (*he); |
1833 | ANHE_at_cache (*he); |
1771 | } |
1834 | } |
1772 | } |
1835 | } |
1773 | |
1836 | |
1774 | mn_now = ev_rt_now; |
1837 | mn_now = ev_rt_now; |
1775 | } |
1838 | } |
… | |
… | |
2000 | if (expect_false (ev_is_active (w))) |
2063 | if (expect_false (ev_is_active (w))) |
2001 | return; |
2064 | return; |
2002 | |
2065 | |
2003 | assert (("ev_io_start called with negative fd", fd >= 0)); |
2066 | assert (("ev_io_start called with negative fd", fd >= 0)); |
2004 | |
2067 | |
|
|
2068 | EV_FREQUENT_CHECK; |
|
|
2069 | |
2005 | ev_start (EV_A_ (W)w, 1); |
2070 | ev_start (EV_A_ (W)w, 1); |
2006 | array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init); |
2071 | array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init); |
2007 | wlist_add (&anfds[fd].head, (WL)w); |
2072 | wlist_add (&anfds[fd].head, (WL)w); |
2008 | |
2073 | |
2009 | fd_change (EV_A_ fd, w->events & EV_IOFDSET | 1); |
2074 | fd_change (EV_A_ fd, w->events & EV_IOFDSET | 1); |
2010 | w->events &= ~EV_IOFDSET; |
2075 | w->events &= ~EV_IOFDSET; |
|
|
2076 | |
|
|
2077 | EV_FREQUENT_CHECK; |
2011 | } |
2078 | } |
2012 | |
2079 | |
2013 | void noinline |
2080 | void noinline |
2014 | ev_io_stop (EV_P_ ev_io *w) |
2081 | ev_io_stop (EV_P_ ev_io *w) |
2015 | { |
2082 | { |
… | |
… | |
2017 | if (expect_false (!ev_is_active (w))) |
2084 | if (expect_false (!ev_is_active (w))) |
2018 | return; |
2085 | return; |
2019 | |
2086 | |
2020 | assert (("ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
2087 | assert (("ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
2021 | |
2088 | |
|
|
2089 | EV_FREQUENT_CHECK; |
|
|
2090 | |
2022 | wlist_del (&anfds[w->fd].head, (WL)w); |
2091 | wlist_del (&anfds[w->fd].head, (WL)w); |
2023 | ev_stop (EV_A_ (W)w); |
2092 | ev_stop (EV_A_ (W)w); |
2024 | |
2093 | |
2025 | fd_change (EV_A_ w->fd, 1); |
2094 | fd_change (EV_A_ w->fd, 1); |
|
|
2095 | |
|
|
2096 | EV_FREQUENT_CHECK; |
2026 | } |
2097 | } |
2027 | |
2098 | |
2028 | void noinline |
2099 | void noinline |
2029 | ev_timer_start (EV_P_ ev_timer *w) |
2100 | ev_timer_start (EV_P_ ev_timer *w) |
2030 | { |
2101 | { |
… | |
… | |
2033 | |
2104 | |
2034 | ev_at (w) += mn_now; |
2105 | ev_at (w) += mn_now; |
2035 | |
2106 | |
2036 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
2107 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
2037 | |
2108 | |
|
|
2109 | EV_FREQUENT_CHECK; |
|
|
2110 | |
|
|
2111 | ++timercnt; |
2038 | ev_start (EV_A_ (W)w, ++timercnt + HEAP0 - 1); |
2112 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
2039 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); |
2113 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); |
2040 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
2114 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
2041 | ANHE_at_set (timers [ev_active (w)]); |
2115 | ANHE_at_cache (timers [ev_active (w)]); |
2042 | upheap (timers, ev_active (w)); |
2116 | upheap (timers, ev_active (w)); |
|
|
2117 | |
|
|
2118 | EV_FREQUENT_CHECK; |
2043 | |
2119 | |
2044 | /*assert (("internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
2120 | /*assert (("internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
2045 | } |
2121 | } |
2046 | |
2122 | |
2047 | void noinline |
2123 | void noinline |
… | |
… | |
2049 | { |
2125 | { |
2050 | clear_pending (EV_A_ (W)w); |
2126 | clear_pending (EV_A_ (W)w); |
2051 | if (expect_false (!ev_is_active (w))) |
2127 | if (expect_false (!ev_is_active (w))) |
2052 | return; |
2128 | return; |
2053 | |
2129 | |
|
|
2130 | EV_FREQUENT_CHECK; |
|
|
2131 | |
2054 | { |
2132 | { |
2055 | int active = ev_active (w); |
2133 | int active = ev_active (w); |
2056 | |
2134 | |
2057 | assert (("internal timer heap corruption", ANHE_w (timers [active]) == (WT)w)); |
2135 | assert (("internal timer heap corruption", ANHE_w (timers [active]) == (WT)w)); |
2058 | |
2136 | |
|
|
2137 | --timercnt; |
|
|
2138 | |
2059 | if (expect_true (active < timercnt + HEAP0 - 1)) |
2139 | if (expect_true (active < timercnt + HEAP0)) |
2060 | { |
2140 | { |
2061 | timers [active] = timers [timercnt + HEAP0 - 1]; |
2141 | timers [active] = timers [timercnt + HEAP0]; |
2062 | adjustheap (timers, timercnt, active); |
2142 | adjustheap (timers, timercnt, active); |
2063 | } |
2143 | } |
2064 | |
|
|
2065 | --timercnt; |
|
|
2066 | } |
2144 | } |
|
|
2145 | |
|
|
2146 | EV_FREQUENT_CHECK; |
2067 | |
2147 | |
2068 | ev_at (w) -= mn_now; |
2148 | ev_at (w) -= mn_now; |
2069 | |
2149 | |
2070 | ev_stop (EV_A_ (W)w); |
2150 | ev_stop (EV_A_ (W)w); |
2071 | } |
2151 | } |
2072 | |
2152 | |
2073 | void noinline |
2153 | void noinline |
2074 | ev_timer_again (EV_P_ ev_timer *w) |
2154 | ev_timer_again (EV_P_ ev_timer *w) |
2075 | { |
2155 | { |
|
|
2156 | EV_FREQUENT_CHECK; |
|
|
2157 | |
2076 | if (ev_is_active (w)) |
2158 | if (ev_is_active (w)) |
2077 | { |
2159 | { |
2078 | if (w->repeat) |
2160 | if (w->repeat) |
2079 | { |
2161 | { |
2080 | ev_at (w) = mn_now + w->repeat; |
2162 | ev_at (w) = mn_now + w->repeat; |
2081 | ANHE_at_set (timers [ev_active (w)]); |
2163 | ANHE_at_cache (timers [ev_active (w)]); |
2082 | adjustheap (timers, timercnt, ev_active (w)); |
2164 | adjustheap (timers, timercnt, ev_active (w)); |
2083 | } |
2165 | } |
2084 | else |
2166 | else |
2085 | ev_timer_stop (EV_A_ w); |
2167 | ev_timer_stop (EV_A_ w); |
2086 | } |
2168 | } |
2087 | else if (w->repeat) |
2169 | else if (w->repeat) |
2088 | { |
2170 | { |
2089 | ev_at (w) = w->repeat; |
2171 | ev_at (w) = w->repeat; |
2090 | ev_timer_start (EV_A_ w); |
2172 | ev_timer_start (EV_A_ w); |
2091 | } |
2173 | } |
|
|
2174 | |
|
|
2175 | EV_FREQUENT_CHECK; |
2092 | } |
2176 | } |
2093 | |
2177 | |
2094 | #if EV_PERIODIC_ENABLE |
2178 | #if EV_PERIODIC_ENABLE |
2095 | void noinline |
2179 | void noinline |
2096 | ev_periodic_start (EV_P_ ev_periodic *w) |
2180 | ev_periodic_start (EV_P_ ev_periodic *w) |
… | |
… | |
2107 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
2191 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
2108 | } |
2192 | } |
2109 | else |
2193 | else |
2110 | ev_at (w) = w->offset; |
2194 | ev_at (w) = w->offset; |
2111 | |
2195 | |
|
|
2196 | EV_FREQUENT_CHECK; |
|
|
2197 | |
|
|
2198 | ++periodiccnt; |
2112 | ev_start (EV_A_ (W)w, ++periodiccnt + HEAP0 - 1); |
2199 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
2113 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); |
2200 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); |
2114 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
2201 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
2115 | ANHE_at_set (periodics [ev_active (w)]); |
2202 | ANHE_at_cache (periodics [ev_active (w)]); |
2116 | upheap (periodics, ev_active (w)); |
2203 | upheap (periodics, ev_active (w)); |
|
|
2204 | |
|
|
2205 | EV_FREQUENT_CHECK; |
2117 | |
2206 | |
2118 | /*assert (("internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
2207 | /*assert (("internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
2119 | } |
2208 | } |
2120 | |
2209 | |
2121 | void noinline |
2210 | void noinline |
… | |
… | |
2123 | { |
2212 | { |
2124 | clear_pending (EV_A_ (W)w); |
2213 | clear_pending (EV_A_ (W)w); |
2125 | if (expect_false (!ev_is_active (w))) |
2214 | if (expect_false (!ev_is_active (w))) |
2126 | return; |
2215 | return; |
2127 | |
2216 | |
|
|
2217 | EV_FREQUENT_CHECK; |
|
|
2218 | |
2128 | { |
2219 | { |
2129 | int active = ev_active (w); |
2220 | int active = ev_active (w); |
2130 | |
2221 | |
2131 | assert (("internal periodic heap corruption", ANHE_w (periodics [active]) == (WT)w)); |
2222 | assert (("internal periodic heap corruption", ANHE_w (periodics [active]) == (WT)w)); |
2132 | |
2223 | |
|
|
2224 | --periodiccnt; |
|
|
2225 | |
2133 | if (expect_true (active < periodiccnt + HEAP0 - 1)) |
2226 | if (expect_true (active < periodiccnt + HEAP0)) |
2134 | { |
2227 | { |
2135 | periodics [active] = periodics [periodiccnt + HEAP0 - 1]; |
2228 | periodics [active] = periodics [periodiccnt + HEAP0]; |
2136 | adjustheap (periodics, periodiccnt, active); |
2229 | adjustheap (periodics, periodiccnt, active); |
2137 | } |
2230 | } |
2138 | |
|
|
2139 | --periodiccnt; |
|
|
2140 | } |
2231 | } |
|
|
2232 | |
|
|
2233 | EV_FREQUENT_CHECK; |
2141 | |
2234 | |
2142 | ev_stop (EV_A_ (W)w); |
2235 | ev_stop (EV_A_ (W)w); |
2143 | } |
2236 | } |
2144 | |
2237 | |
2145 | void noinline |
2238 | void noinline |
… | |
… | |
2165 | return; |
2258 | return; |
2166 | |
2259 | |
2167 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
2260 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
2168 | |
2261 | |
2169 | evpipe_init (EV_A); |
2262 | evpipe_init (EV_A); |
|
|
2263 | |
|
|
2264 | EV_FREQUENT_CHECK; |
2170 | |
2265 | |
2171 | { |
2266 | { |
2172 | #ifndef _WIN32 |
2267 | #ifndef _WIN32 |
2173 | sigset_t full, prev; |
2268 | sigset_t full, prev; |
2174 | sigfillset (&full); |
2269 | sigfillset (&full); |
… | |
… | |
2195 | sigfillset (&sa.sa_mask); |
2290 | sigfillset (&sa.sa_mask); |
2196 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
2291 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
2197 | sigaction (w->signum, &sa, 0); |
2292 | sigaction (w->signum, &sa, 0); |
2198 | #endif |
2293 | #endif |
2199 | } |
2294 | } |
|
|
2295 | |
|
|
2296 | EV_FREQUENT_CHECK; |
2200 | } |
2297 | } |
2201 | |
2298 | |
2202 | void noinline |
2299 | void noinline |
2203 | ev_signal_stop (EV_P_ ev_signal *w) |
2300 | ev_signal_stop (EV_P_ ev_signal *w) |
2204 | { |
2301 | { |
2205 | clear_pending (EV_A_ (W)w); |
2302 | clear_pending (EV_A_ (W)w); |
2206 | if (expect_false (!ev_is_active (w))) |
2303 | if (expect_false (!ev_is_active (w))) |
2207 | return; |
2304 | return; |
2208 | |
2305 | |
|
|
2306 | EV_FREQUENT_CHECK; |
|
|
2307 | |
2209 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
2308 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
2210 | ev_stop (EV_A_ (W)w); |
2309 | ev_stop (EV_A_ (W)w); |
2211 | |
2310 | |
2212 | if (!signals [w->signum - 1].head) |
2311 | if (!signals [w->signum - 1].head) |
2213 | signal (w->signum, SIG_DFL); |
2312 | signal (w->signum, SIG_DFL); |
|
|
2313 | |
|
|
2314 | EV_FREQUENT_CHECK; |
2214 | } |
2315 | } |
2215 | |
2316 | |
2216 | void |
2317 | void |
2217 | ev_child_start (EV_P_ ev_child *w) |
2318 | ev_child_start (EV_P_ ev_child *w) |
2218 | { |
2319 | { |
… | |
… | |
2220 | assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
2321 | assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
2221 | #endif |
2322 | #endif |
2222 | if (expect_false (ev_is_active (w))) |
2323 | if (expect_false (ev_is_active (w))) |
2223 | return; |
2324 | return; |
2224 | |
2325 | |
|
|
2326 | EV_FREQUENT_CHECK; |
|
|
2327 | |
2225 | ev_start (EV_A_ (W)w, 1); |
2328 | ev_start (EV_A_ (W)w, 1); |
2226 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2329 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
|
|
2330 | |
|
|
2331 | EV_FREQUENT_CHECK; |
2227 | } |
2332 | } |
2228 | |
2333 | |
2229 | void |
2334 | void |
2230 | ev_child_stop (EV_P_ ev_child *w) |
2335 | ev_child_stop (EV_P_ ev_child *w) |
2231 | { |
2336 | { |
2232 | clear_pending (EV_A_ (W)w); |
2337 | clear_pending (EV_A_ (W)w); |
2233 | if (expect_false (!ev_is_active (w))) |
2338 | if (expect_false (!ev_is_active (w))) |
2234 | return; |
2339 | return; |
2235 | |
2340 | |
|
|
2341 | EV_FREQUENT_CHECK; |
|
|
2342 | |
2236 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2343 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2237 | ev_stop (EV_A_ (W)w); |
2344 | ev_stop (EV_A_ (W)w); |
|
|
2345 | |
|
|
2346 | EV_FREQUENT_CHECK; |
2238 | } |
2347 | } |
2239 | |
2348 | |
2240 | #if EV_STAT_ENABLE |
2349 | #if EV_STAT_ENABLE |
2241 | |
2350 | |
2242 | # ifdef _WIN32 |
2351 | # ifdef _WIN32 |
… | |
… | |
2470 | else |
2579 | else |
2471 | #endif |
2580 | #endif |
2472 | ev_timer_start (EV_A_ &w->timer); |
2581 | ev_timer_start (EV_A_ &w->timer); |
2473 | |
2582 | |
2474 | ev_start (EV_A_ (W)w, 1); |
2583 | ev_start (EV_A_ (W)w, 1); |
|
|
2584 | |
|
|
2585 | EV_FREQUENT_CHECK; |
2475 | } |
2586 | } |
2476 | |
2587 | |
2477 | void |
2588 | void |
2478 | ev_stat_stop (EV_P_ ev_stat *w) |
2589 | ev_stat_stop (EV_P_ ev_stat *w) |
2479 | { |
2590 | { |
2480 | clear_pending (EV_A_ (W)w); |
2591 | clear_pending (EV_A_ (W)w); |
2481 | if (expect_false (!ev_is_active (w))) |
2592 | if (expect_false (!ev_is_active (w))) |
2482 | return; |
2593 | return; |
2483 | |
2594 | |
|
|
2595 | EV_FREQUENT_CHECK; |
|
|
2596 | |
2484 | #if EV_USE_INOTIFY |
2597 | #if EV_USE_INOTIFY |
2485 | infy_del (EV_A_ w); |
2598 | infy_del (EV_A_ w); |
2486 | #endif |
2599 | #endif |
2487 | ev_timer_stop (EV_A_ &w->timer); |
2600 | ev_timer_stop (EV_A_ &w->timer); |
2488 | |
2601 | |
2489 | ev_stop (EV_A_ (W)w); |
2602 | ev_stop (EV_A_ (W)w); |
|
|
2603 | |
|
|
2604 | EV_FREQUENT_CHECK; |
2490 | } |
2605 | } |
2491 | #endif |
2606 | #endif |
2492 | |
2607 | |
2493 | #if EV_IDLE_ENABLE |
2608 | #if EV_IDLE_ENABLE |
2494 | void |
2609 | void |
… | |
… | |
2496 | { |
2611 | { |
2497 | if (expect_false (ev_is_active (w))) |
2612 | if (expect_false (ev_is_active (w))) |
2498 | return; |
2613 | return; |
2499 | |
2614 | |
2500 | pri_adjust (EV_A_ (W)w); |
2615 | pri_adjust (EV_A_ (W)w); |
|
|
2616 | |
|
|
2617 | EV_FREQUENT_CHECK; |
2501 | |
2618 | |
2502 | { |
2619 | { |
2503 | int active = ++idlecnt [ABSPRI (w)]; |
2620 | int active = ++idlecnt [ABSPRI (w)]; |
2504 | |
2621 | |
2505 | ++idleall; |
2622 | ++idleall; |
2506 | ev_start (EV_A_ (W)w, active); |
2623 | ev_start (EV_A_ (W)w, active); |
2507 | |
2624 | |
2508 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
2625 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
2509 | idles [ABSPRI (w)][active - 1] = w; |
2626 | idles [ABSPRI (w)][active - 1] = w; |
2510 | } |
2627 | } |
|
|
2628 | |
|
|
2629 | EV_FREQUENT_CHECK; |
2511 | } |
2630 | } |
2512 | |
2631 | |
2513 | void |
2632 | void |
2514 | ev_idle_stop (EV_P_ ev_idle *w) |
2633 | ev_idle_stop (EV_P_ ev_idle *w) |
2515 | { |
2634 | { |
2516 | clear_pending (EV_A_ (W)w); |
2635 | clear_pending (EV_A_ (W)w); |
2517 | if (expect_false (!ev_is_active (w))) |
2636 | if (expect_false (!ev_is_active (w))) |
2518 | return; |
2637 | return; |
2519 | |
2638 | |
|
|
2639 | EV_FREQUENT_CHECK; |
|
|
2640 | |
2520 | { |
2641 | { |
2521 | int active = ev_active (w); |
2642 | int active = ev_active (w); |
2522 | |
2643 | |
2523 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
2644 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
2524 | ev_active (idles [ABSPRI (w)][active - 1]) = active; |
2645 | ev_active (idles [ABSPRI (w)][active - 1]) = active; |
2525 | |
2646 | |
2526 | ev_stop (EV_A_ (W)w); |
2647 | ev_stop (EV_A_ (W)w); |
2527 | --idleall; |
2648 | --idleall; |
2528 | } |
2649 | } |
|
|
2650 | |
|
|
2651 | EV_FREQUENT_CHECK; |
2529 | } |
2652 | } |
2530 | #endif |
2653 | #endif |
2531 | |
2654 | |
2532 | void |
2655 | void |
2533 | ev_prepare_start (EV_P_ ev_prepare *w) |
2656 | ev_prepare_start (EV_P_ ev_prepare *w) |
2534 | { |
2657 | { |
2535 | if (expect_false (ev_is_active (w))) |
2658 | if (expect_false (ev_is_active (w))) |
2536 | return; |
2659 | return; |
|
|
2660 | |
|
|
2661 | EV_FREQUENT_CHECK; |
2537 | |
2662 | |
2538 | ev_start (EV_A_ (W)w, ++preparecnt); |
2663 | ev_start (EV_A_ (W)w, ++preparecnt); |
2539 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
2664 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
2540 | prepares [preparecnt - 1] = w; |
2665 | prepares [preparecnt - 1] = w; |
|
|
2666 | |
|
|
2667 | EV_FREQUENT_CHECK; |
2541 | } |
2668 | } |
2542 | |
2669 | |
2543 | void |
2670 | void |
2544 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2671 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2545 | { |
2672 | { |
2546 | clear_pending (EV_A_ (W)w); |
2673 | clear_pending (EV_A_ (W)w); |
2547 | if (expect_false (!ev_is_active (w))) |
2674 | if (expect_false (!ev_is_active (w))) |
2548 | return; |
2675 | return; |
2549 | |
2676 | |
|
|
2677 | EV_FREQUENT_CHECK; |
|
|
2678 | |
2550 | { |
2679 | { |
2551 | int active = ev_active (w); |
2680 | int active = ev_active (w); |
2552 | |
2681 | |
2553 | prepares [active - 1] = prepares [--preparecnt]; |
2682 | prepares [active - 1] = prepares [--preparecnt]; |
2554 | ev_active (prepares [active - 1]) = active; |
2683 | ev_active (prepares [active - 1]) = active; |
2555 | } |
2684 | } |
2556 | |
2685 | |
2557 | ev_stop (EV_A_ (W)w); |
2686 | ev_stop (EV_A_ (W)w); |
|
|
2687 | |
|
|
2688 | EV_FREQUENT_CHECK; |
2558 | } |
2689 | } |
2559 | |
2690 | |
2560 | void |
2691 | void |
2561 | ev_check_start (EV_P_ ev_check *w) |
2692 | ev_check_start (EV_P_ ev_check *w) |
2562 | { |
2693 | { |
2563 | if (expect_false (ev_is_active (w))) |
2694 | if (expect_false (ev_is_active (w))) |
2564 | return; |
2695 | return; |
|
|
2696 | |
|
|
2697 | EV_FREQUENT_CHECK; |
2565 | |
2698 | |
2566 | ev_start (EV_A_ (W)w, ++checkcnt); |
2699 | ev_start (EV_A_ (W)w, ++checkcnt); |
2567 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
2700 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
2568 | checks [checkcnt - 1] = w; |
2701 | checks [checkcnt - 1] = w; |
|
|
2702 | |
|
|
2703 | EV_FREQUENT_CHECK; |
2569 | } |
2704 | } |
2570 | |
2705 | |
2571 | void |
2706 | void |
2572 | ev_check_stop (EV_P_ ev_check *w) |
2707 | ev_check_stop (EV_P_ ev_check *w) |
2573 | { |
2708 | { |
2574 | clear_pending (EV_A_ (W)w); |
2709 | clear_pending (EV_A_ (W)w); |
2575 | if (expect_false (!ev_is_active (w))) |
2710 | if (expect_false (!ev_is_active (w))) |
2576 | return; |
2711 | return; |
2577 | |
2712 | |
|
|
2713 | EV_FREQUENT_CHECK; |
|
|
2714 | |
2578 | { |
2715 | { |
2579 | int active = ev_active (w); |
2716 | int active = ev_active (w); |
2580 | |
2717 | |
2581 | checks [active - 1] = checks [--checkcnt]; |
2718 | checks [active - 1] = checks [--checkcnt]; |
2582 | ev_active (checks [active - 1]) = active; |
2719 | ev_active (checks [active - 1]) = active; |
2583 | } |
2720 | } |
2584 | |
2721 | |
2585 | ev_stop (EV_A_ (W)w); |
2722 | ev_stop (EV_A_ (W)w); |
|
|
2723 | |
|
|
2724 | EV_FREQUENT_CHECK; |
2586 | } |
2725 | } |
2587 | |
2726 | |
2588 | #if EV_EMBED_ENABLE |
2727 | #if EV_EMBED_ENABLE |
2589 | void noinline |
2728 | void noinline |
2590 | ev_embed_sweep (EV_P_ ev_embed *w) |
2729 | ev_embed_sweep (EV_P_ ev_embed *w) |
… | |
… | |
2637 | struct ev_loop *loop = w->other; |
2776 | struct ev_loop *loop = w->other; |
2638 | assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
2777 | assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
2639 | ev_io_init (&w->io, embed_io_cb, backend_fd, EV_READ); |
2778 | ev_io_init (&w->io, embed_io_cb, backend_fd, EV_READ); |
2640 | } |
2779 | } |
2641 | |
2780 | |
|
|
2781 | EV_FREQUENT_CHECK; |
|
|
2782 | |
2642 | ev_set_priority (&w->io, ev_priority (w)); |
2783 | ev_set_priority (&w->io, ev_priority (w)); |
2643 | ev_io_start (EV_A_ &w->io); |
2784 | ev_io_start (EV_A_ &w->io); |
2644 | |
2785 | |
2645 | ev_prepare_init (&w->prepare, embed_prepare_cb); |
2786 | ev_prepare_init (&w->prepare, embed_prepare_cb); |
2646 | ev_set_priority (&w->prepare, EV_MINPRI); |
2787 | ev_set_priority (&w->prepare, EV_MINPRI); |
2647 | ev_prepare_start (EV_A_ &w->prepare); |
2788 | ev_prepare_start (EV_A_ &w->prepare); |
2648 | |
2789 | |
2649 | /*ev_idle_init (&w->idle, e,bed_idle_cb);*/ |
2790 | /*ev_idle_init (&w->idle, e,bed_idle_cb);*/ |
2650 | |
2791 | |
2651 | ev_start (EV_A_ (W)w, 1); |
2792 | ev_start (EV_A_ (W)w, 1); |
|
|
2793 | |
|
|
2794 | EV_FREQUENT_CHECK; |
2652 | } |
2795 | } |
2653 | |
2796 | |
2654 | void |
2797 | void |
2655 | ev_embed_stop (EV_P_ ev_embed *w) |
2798 | ev_embed_stop (EV_P_ ev_embed *w) |
2656 | { |
2799 | { |
2657 | clear_pending (EV_A_ (W)w); |
2800 | clear_pending (EV_A_ (W)w); |
2658 | if (expect_false (!ev_is_active (w))) |
2801 | if (expect_false (!ev_is_active (w))) |
2659 | return; |
2802 | return; |
2660 | |
2803 | |
|
|
2804 | EV_FREQUENT_CHECK; |
|
|
2805 | |
2661 | ev_io_stop (EV_A_ &w->io); |
2806 | ev_io_stop (EV_A_ &w->io); |
2662 | ev_prepare_stop (EV_A_ &w->prepare); |
2807 | ev_prepare_stop (EV_A_ &w->prepare); |
2663 | |
2808 | |
2664 | ev_stop (EV_A_ (W)w); |
2809 | ev_stop (EV_A_ (W)w); |
|
|
2810 | |
|
|
2811 | EV_FREQUENT_CHECK; |
2665 | } |
2812 | } |
2666 | #endif |
2813 | #endif |
2667 | |
2814 | |
2668 | #if EV_FORK_ENABLE |
2815 | #if EV_FORK_ENABLE |
2669 | void |
2816 | void |
2670 | ev_fork_start (EV_P_ ev_fork *w) |
2817 | ev_fork_start (EV_P_ ev_fork *w) |
2671 | { |
2818 | { |
2672 | if (expect_false (ev_is_active (w))) |
2819 | if (expect_false (ev_is_active (w))) |
2673 | return; |
2820 | return; |
|
|
2821 | |
|
|
2822 | EV_FREQUENT_CHECK; |
2674 | |
2823 | |
2675 | ev_start (EV_A_ (W)w, ++forkcnt); |
2824 | ev_start (EV_A_ (W)w, ++forkcnt); |
2676 | array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); |
2825 | array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); |
2677 | forks [forkcnt - 1] = w; |
2826 | forks [forkcnt - 1] = w; |
|
|
2827 | |
|
|
2828 | EV_FREQUENT_CHECK; |
2678 | } |
2829 | } |
2679 | |
2830 | |
2680 | void |
2831 | void |
2681 | ev_fork_stop (EV_P_ ev_fork *w) |
2832 | ev_fork_stop (EV_P_ ev_fork *w) |
2682 | { |
2833 | { |
2683 | clear_pending (EV_A_ (W)w); |
2834 | clear_pending (EV_A_ (W)w); |
2684 | if (expect_false (!ev_is_active (w))) |
2835 | if (expect_false (!ev_is_active (w))) |
2685 | return; |
2836 | return; |
2686 | |
2837 | |
|
|
2838 | EV_FREQUENT_CHECK; |
|
|
2839 | |
2687 | { |
2840 | { |
2688 | int active = ev_active (w); |
2841 | int active = ev_active (w); |
2689 | |
2842 | |
2690 | forks [active - 1] = forks [--forkcnt]; |
2843 | forks [active - 1] = forks [--forkcnt]; |
2691 | ev_active (forks [active - 1]) = active; |
2844 | ev_active (forks [active - 1]) = active; |
2692 | } |
2845 | } |
2693 | |
2846 | |
2694 | ev_stop (EV_A_ (W)w); |
2847 | ev_stop (EV_A_ (W)w); |
|
|
2848 | |
|
|
2849 | EV_FREQUENT_CHECK; |
2695 | } |
2850 | } |
2696 | #endif |
2851 | #endif |
2697 | |
2852 | |
2698 | #if EV_ASYNC_ENABLE |
2853 | #if EV_ASYNC_ENABLE |
2699 | void |
2854 | void |
… | |
… | |
2701 | { |
2856 | { |
2702 | if (expect_false (ev_is_active (w))) |
2857 | if (expect_false (ev_is_active (w))) |
2703 | return; |
2858 | return; |
2704 | |
2859 | |
2705 | evpipe_init (EV_A); |
2860 | evpipe_init (EV_A); |
|
|
2861 | |
|
|
2862 | EV_FREQUENT_CHECK; |
2706 | |
2863 | |
2707 | ev_start (EV_A_ (W)w, ++asynccnt); |
2864 | ev_start (EV_A_ (W)w, ++asynccnt); |
2708 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); |
2865 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); |
2709 | asyncs [asynccnt - 1] = w; |
2866 | asyncs [asynccnt - 1] = w; |
|
|
2867 | |
|
|
2868 | EV_FREQUENT_CHECK; |
2710 | } |
2869 | } |
2711 | |
2870 | |
2712 | void |
2871 | void |
2713 | ev_async_stop (EV_P_ ev_async *w) |
2872 | ev_async_stop (EV_P_ ev_async *w) |
2714 | { |
2873 | { |
2715 | clear_pending (EV_A_ (W)w); |
2874 | clear_pending (EV_A_ (W)w); |
2716 | if (expect_false (!ev_is_active (w))) |
2875 | if (expect_false (!ev_is_active (w))) |
2717 | return; |
2876 | return; |
2718 | |
2877 | |
|
|
2878 | EV_FREQUENT_CHECK; |
|
|
2879 | |
2719 | { |
2880 | { |
2720 | int active = ev_active (w); |
2881 | int active = ev_active (w); |
2721 | |
2882 | |
2722 | asyncs [active - 1] = asyncs [--asynccnt]; |
2883 | asyncs [active - 1] = asyncs [--asynccnt]; |
2723 | ev_active (asyncs [active - 1]) = active; |
2884 | ev_active (asyncs [active - 1]) = active; |
2724 | } |
2885 | } |
2725 | |
2886 | |
2726 | ev_stop (EV_A_ (W)w); |
2887 | ev_stop (EV_A_ (W)w); |
|
|
2888 | |
|
|
2889 | EV_FREQUENT_CHECK; |
2727 | } |
2890 | } |
2728 | |
2891 | |
2729 | void |
2892 | void |
2730 | ev_async_send (EV_P_ ev_async *w) |
2893 | ev_async_send (EV_P_ ev_async *w) |
2731 | { |
2894 | { |