… | |
… | |
422 | W w; |
422 | W w; |
423 | int events; |
423 | int events; |
424 | } ANPENDING; |
424 | } ANPENDING; |
425 | |
425 | |
426 | #if EV_USE_INOTIFY |
426 | #if EV_USE_INOTIFY |
|
|
427 | /* hash table entry per inotify-id */ |
427 | typedef struct |
428 | typedef struct |
428 | { |
429 | { |
429 | WL head; |
430 | WL head; |
430 | } ANFS; |
431 | } ANFS; |
|
|
432 | #endif |
|
|
433 | |
|
|
434 | /* Heap Entry */ |
|
|
435 | #if EV_HEAP_CACHE_AT |
|
|
436 | typedef struct { |
|
|
437 | WT w; |
|
|
438 | ev_tstamp at; |
|
|
439 | } ANHE; |
|
|
440 | |
|
|
441 | #define ANHE_w(he) (he) /* access watcher, read-write */ |
|
|
442 | #define ANHE_at(he) (he)->at /* acces cahced at, read-only */ |
|
|
443 | #define ANHE_at_set(he) (he)->at = (he)->w->at /* update at from watcher */ |
|
|
444 | #else |
|
|
445 | typedef WT ANHE; |
|
|
446 | |
|
|
447 | #define ANHE_w(he) (he) |
|
|
448 | #define ANHE_at(he) (he)->at |
|
|
449 | #define ANHE_at_set(he) |
431 | #endif |
450 | #endif |
432 | |
451 | |
433 | #if EV_MULTIPLICITY |
452 | #if EV_MULTIPLICITY |
434 | |
453 | |
435 | struct ev_loop |
454 | struct ev_loop |
… | |
… | |
520 | } |
539 | } |
521 | } |
540 | } |
522 | |
541 | |
523 | /*****************************************************************************/ |
542 | /*****************************************************************************/ |
524 | |
543 | |
|
|
544 | #define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ |
|
|
545 | |
525 | int inline_size |
546 | int inline_size |
526 | array_nextsize (int elem, int cur, int cnt) |
547 | array_nextsize (int elem, int cur, int cnt) |
527 | { |
548 | { |
528 | int ncur = cur + 1; |
549 | int ncur = cur + 1; |
529 | |
550 | |
530 | do |
551 | do |
531 | ncur <<= 1; |
552 | ncur <<= 1; |
532 | while (cnt > ncur); |
553 | while (cnt > ncur); |
533 | |
554 | |
534 | /* if size > 4096, round to 4096 - 4 * longs to accomodate malloc overhead */ |
555 | /* if size is large, round to MALLOC_ROUND - 4 * longs to accomodate malloc overhead */ |
535 | if (elem * ncur > 4096) |
556 | if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4) |
536 | { |
557 | { |
537 | ncur *= elem; |
558 | ncur *= elem; |
538 | ncur = (ncur + elem + 4095 + sizeof (void *) * 4) & ~4095; |
559 | ncur = (ncur + elem + (MALLOC_ROUND - 1) + sizeof (void *) * 4) & ~(MALLOC_ROUND - 1); |
539 | ncur = ncur - sizeof (void *) * 4; |
560 | ncur = ncur - sizeof (void *) * 4; |
540 | ncur /= elem; |
561 | ncur /= elem; |
541 | } |
562 | } |
542 | |
563 | |
543 | return ncur; |
564 | return ncur; |
… | |
… | |
757 | } |
778 | } |
758 | } |
779 | } |
759 | |
780 | |
760 | /*****************************************************************************/ |
781 | /*****************************************************************************/ |
761 | |
782 | |
|
|
783 | /* |
|
|
784 | * the heap functions want a real array index. array index 0 uis guaranteed to not |
|
|
785 | * be in-use at any time. the first heap entry is at array [HEAP0]. DHEAP gives |
|
|
786 | * the branching factor of the d-tree. |
|
|
787 | */ |
|
|
788 | |
|
|
789 | /* |
|
|
790 | * at the moment we allow libev the luxury of two heaps, |
|
|
791 | * a small-code-size 2-heap one and a ~1.5kb larger 4-heap |
|
|
792 | * which is more cache-efficient. |
|
|
793 | * the difference is about 5% with 50000+ watchers. |
|
|
794 | */ |
|
|
795 | #define EV_USE_4HEAP !EV_MINIMAL |
|
|
796 | #if EV_USE_4HEAP |
|
|
797 | |
|
|
798 | #define DHEAP 4 |
|
|
799 | #define HEAP0 (DHEAP - 1) /* index of first element in heap */ |
|
|
800 | |
762 | /* towards the root */ |
801 | /* towards the root */ |
763 | void inline_speed |
802 | void inline_speed |
764 | upheap (WT *heap, int k) |
803 | upheap (ANHE *heap, int k) |
765 | { |
804 | { |
766 | WT w = heap [k]; |
805 | ANHE he = heap [k]; |
767 | |
806 | |
768 | for (;;) |
807 | for (;;) |
769 | { |
808 | { |
770 | int p = k >> 1; |
809 | int p = ((k - HEAP0 - 1) / DHEAP) + HEAP0; |
771 | |
810 | |
772 | /* maybe we could use a dummy element at heap [0]? */ |
811 | if (p == k || ANHE_at (heap [p]) <= ANHE_at (he)) |
773 | if (!p || heap [p]->at <= w->at) |
|
|
774 | break; |
812 | break; |
775 | |
813 | |
776 | heap [k] = heap [p]; |
814 | heap [k] = heap [p]; |
777 | ev_active (heap [k]) = k; |
815 | ev_active (ANHE_w (heap [k])) = k; |
778 | k = p; |
816 | k = p; |
779 | } |
817 | } |
780 | |
818 | |
|
|
819 | ev_active (ANHE_w (he)) = k; |
781 | heap [k] = w; |
820 | heap [k] = he; |
782 | ev_active (heap [k]) = k; |
|
|
783 | } |
821 | } |
784 | |
822 | |
785 | /* away from the root */ |
823 | /* away from the root */ |
786 | void inline_speed |
824 | void inline_speed |
787 | downheap (WT *heap, int N, int k) |
825 | downheap (ANHE *heap, int N, int k) |
788 | { |
826 | { |
789 | WT w = heap [k]; |
827 | ANHE he = heap [k]; |
|
|
828 | ANHE *E = heap + N + HEAP0; |
|
|
829 | |
|
|
830 | for (;;) |
|
|
831 | { |
|
|
832 | ev_tstamp minat; |
|
|
833 | ANHE *minpos; |
|
|
834 | ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0; |
|
|
835 | |
|
|
836 | // find minimum child |
|
|
837 | if (expect_true (pos + DHEAP - 1 < E)) |
|
|
838 | { |
|
|
839 | /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
|
|
840 | if (ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
|
|
841 | if (ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos)); |
|
|
842 | if (ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos)); |
|
|
843 | } |
|
|
844 | else if (pos < E) |
|
|
845 | { |
|
|
846 | /* slow path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
|
|
847 | if (pos + 1 < E && ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
|
|
848 | if (pos + 2 < E && ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos)); |
|
|
849 | if (pos + 3 < E && ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos)); |
|
|
850 | } |
|
|
851 | else |
|
|
852 | break; |
|
|
853 | |
|
|
854 | if (ANHE_at (he) <= minat) |
|
|
855 | break; |
|
|
856 | |
|
|
857 | ev_active (ANHE_w (*minpos)) = k; |
|
|
858 | heap [k] = *minpos; |
|
|
859 | |
|
|
860 | k = minpos - heap; |
|
|
861 | } |
|
|
862 | |
|
|
863 | ev_active (ANHE_w (he)) = k; |
|
|
864 | heap [k] = he; |
|
|
865 | } |
|
|
866 | |
|
|
867 | #else // 4HEAP |
|
|
868 | |
|
|
869 | #define HEAP0 1 |
|
|
870 | |
|
|
871 | /* towards the root */ |
|
|
872 | void inline_speed |
|
|
873 | upheap (ANHE *heap, int k) |
|
|
874 | { |
|
|
875 | ANHE he = heap [k]; |
|
|
876 | |
|
|
877 | for (;;) |
|
|
878 | { |
|
|
879 | int p = k >> 1; |
|
|
880 | |
|
|
881 | /* maybe we could use a dummy element at heap [0]? */ |
|
|
882 | if (!p || ANHE_at (heap [p]) <= ANHE_at (he)) |
|
|
883 | break; |
|
|
884 | |
|
|
885 | heap [k] = heap [p]; |
|
|
886 | ev_active (ANHE_w (heap [k])) = k; |
|
|
887 | k = p; |
|
|
888 | } |
|
|
889 | |
|
|
890 | heap [k] = w; |
|
|
891 | ev_active (ANHE_w (heap [k])) = k; |
|
|
892 | } |
|
|
893 | |
|
|
894 | /* away from the root */ |
|
|
895 | void inline_speed |
|
|
896 | downheap (ANHE *heap, int N, int k) |
|
|
897 | { |
|
|
898 | ANHE he = heap [k]; |
790 | |
899 | |
791 | for (;;) |
900 | for (;;) |
792 | { |
901 | { |
793 | int c = k << 1; |
902 | int c = k << 1; |
794 | |
903 | |
795 | if (c > N) |
904 | if (c > N) |
796 | break; |
905 | break; |
797 | |
906 | |
798 | c += c < N && heap [c]->at > heap [c + 1]->at |
907 | c += c + 1 < N && ANHE_at (heap [c]) > ANHE_at (heap [c + 1]) |
799 | ? 1 : 0; |
908 | ? 1 : 0; |
800 | |
909 | |
801 | if (w->at <= heap [c]->at) |
910 | if (w->at <= ANHE_at (heap [c])) |
802 | break; |
911 | break; |
803 | |
912 | |
804 | heap [k] = heap [c]; |
913 | heap [k] = heap [c]; |
805 | ev_active (heap [k]) = k; |
914 | ev_active (ANHE_w (heap [k])) = k; |
806 | |
915 | |
807 | k = c; |
916 | k = c; |
808 | } |
917 | } |
809 | |
918 | |
810 | heap [k] = w; |
919 | heap [k] = he; |
811 | ev_active (heap [k]) = k; |
920 | ev_active (ANHE_w (he)) = k; |
812 | } |
921 | } |
|
|
922 | #endif |
813 | |
923 | |
814 | void inline_size |
924 | void inline_size |
815 | adjustheap (WT *heap, int N, int k) |
925 | adjustheap (ANHE *heap, int N, int k) |
816 | { |
926 | { |
817 | upheap (heap, k); |
927 | upheap (heap, k); |
818 | downheap (heap, N, k); |
928 | downheap (heap, N, k); |
819 | } |
929 | } |
820 | |
930 | |
… | |
… | |
912 | pipecb (EV_P_ ev_io *iow, int revents) |
1022 | pipecb (EV_P_ ev_io *iow, int revents) |
913 | { |
1023 | { |
914 | #if EV_USE_EVENTFD |
1024 | #if EV_USE_EVENTFD |
915 | if (evfd >= 0) |
1025 | if (evfd >= 0) |
916 | { |
1026 | { |
917 | uint64_t counter = 1; |
1027 | uint64_t counter; |
918 | read (evfd, &counter, sizeof (uint64_t)); |
1028 | read (evfd, &counter, sizeof (uint64_t)); |
919 | } |
1029 | } |
920 | else |
1030 | else |
921 | #endif |
1031 | #endif |
922 | { |
1032 | { |
… | |
… | |
1368 | void |
1478 | void |
1369 | ev_loop_fork (EV_P) |
1479 | ev_loop_fork (EV_P) |
1370 | { |
1480 | { |
1371 | postfork = 1; /* must be in line with ev_default_fork */ |
1481 | postfork = 1; /* must be in line with ev_default_fork */ |
1372 | } |
1482 | } |
1373 | |
|
|
1374 | #endif |
1483 | #endif |
1375 | |
1484 | |
1376 | #if EV_MULTIPLICITY |
1485 | #if EV_MULTIPLICITY |
1377 | struct ev_loop * |
1486 | struct ev_loop * |
1378 | ev_default_loop_init (unsigned int flags) |
1487 | ev_default_loop_init (unsigned int flags) |
… | |
… | |
1459 | EV_CB_INVOKE (p->w, p->events); |
1568 | EV_CB_INVOKE (p->w, p->events); |
1460 | } |
1569 | } |
1461 | } |
1570 | } |
1462 | } |
1571 | } |
1463 | |
1572 | |
|
|
1573 | #if EV_IDLE_ENABLE |
|
|
1574 | void inline_size |
|
|
1575 | idle_reify (EV_P) |
|
|
1576 | { |
|
|
1577 | if (expect_false (idleall)) |
|
|
1578 | { |
|
|
1579 | int pri; |
|
|
1580 | |
|
|
1581 | for (pri = NUMPRI; pri--; ) |
|
|
1582 | { |
|
|
1583 | if (pendingcnt [pri]) |
|
|
1584 | break; |
|
|
1585 | |
|
|
1586 | if (idlecnt [pri]) |
|
|
1587 | { |
|
|
1588 | queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE); |
|
|
1589 | break; |
|
|
1590 | } |
|
|
1591 | } |
|
|
1592 | } |
|
|
1593 | } |
|
|
1594 | #endif |
|
|
1595 | |
1464 | void inline_size |
1596 | void inline_size |
1465 | timers_reify (EV_P) |
1597 | timers_reify (EV_P) |
1466 | { |
1598 | { |
1467 | while (timercnt && ev_at (timers [1]) <= mn_now) |
1599 | while (timercnt && ANHE_at (timers [HEAP0]) <= mn_now) |
1468 | { |
1600 | { |
1469 | ev_timer *w = (ev_timer *)timers [1]; |
1601 | ev_timer *w = (ev_timer *)ANHE_w (timers [HEAP0]); |
1470 | |
1602 | |
1471 | /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ |
1603 | /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ |
1472 | |
1604 | |
1473 | /* first reschedule or stop timer */ |
1605 | /* first reschedule or stop timer */ |
1474 | if (w->repeat) |
1606 | if (w->repeat) |
… | |
… | |
1477 | |
1609 | |
1478 | ev_at (w) += w->repeat; |
1610 | ev_at (w) += w->repeat; |
1479 | if (ev_at (w) < mn_now) |
1611 | if (ev_at (w) < mn_now) |
1480 | ev_at (w) = mn_now; |
1612 | ev_at (w) = mn_now; |
1481 | |
1613 | |
1482 | downheap (timers, timercnt, 1); |
1614 | downheap (timers, timercnt, HEAP0); |
1483 | } |
1615 | } |
1484 | else |
1616 | else |
1485 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1617 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1486 | |
1618 | |
1487 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
1619 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
… | |
… | |
1490 | |
1622 | |
1491 | #if EV_PERIODIC_ENABLE |
1623 | #if EV_PERIODIC_ENABLE |
1492 | void inline_size |
1624 | void inline_size |
1493 | periodics_reify (EV_P) |
1625 | periodics_reify (EV_P) |
1494 | { |
1626 | { |
1495 | while (periodiccnt && ev_at (periodics [1]) <= ev_rt_now) |
1627 | while (periodiccnt && ANHE_at (periodics [HEAP0]) <= ev_rt_now) |
1496 | { |
1628 | { |
1497 | ev_periodic *w = (ev_periodic *)periodics [1]; |
1629 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); |
1498 | |
1630 | |
1499 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1631 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1500 | |
1632 | |
1501 | /* first reschedule or stop timer */ |
1633 | /* first reschedule or stop timer */ |
1502 | if (w->reschedule_cb) |
1634 | if (w->reschedule_cb) |
… | |
… | |
1508 | else if (w->interval) |
1640 | else if (w->interval) |
1509 | { |
1641 | { |
1510 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1642 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1511 | if (ev_at (w) - ev_rt_now <= TIME_EPSILON) ev_at (w) += w->interval; |
1643 | if (ev_at (w) - ev_rt_now <= TIME_EPSILON) ev_at (w) += w->interval; |
1512 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ev_at (w) > ev_rt_now)); |
1644 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ev_at (w) > ev_rt_now)); |
1513 | downheap (periodics, periodiccnt, 1); |
1645 | downheap (periodics, periodiccnt, HEAP0); |
1514 | } |
1646 | } |
1515 | else |
1647 | else |
1516 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1648 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1517 | |
1649 | |
1518 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
1650 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
… | |
… | |
1523 | periodics_reschedule (EV_P) |
1655 | periodics_reschedule (EV_P) |
1524 | { |
1656 | { |
1525 | int i; |
1657 | int i; |
1526 | |
1658 | |
1527 | /* adjust periodics after time jump */ |
1659 | /* adjust periodics after time jump */ |
1528 | for (i = 1; i <= periodiccnt; ++i) |
1660 | for (i = HEAP0; i < periodiccnt + HEAP0; ++i) |
1529 | { |
1661 | { |
1530 | ev_periodic *w = (ev_periodic *)periodics [i]; |
1662 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [i]); |
1531 | |
1663 | |
1532 | if (w->reschedule_cb) |
1664 | if (w->reschedule_cb) |
1533 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
1665 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
1534 | else if (w->interval) |
1666 | else if (w->interval) |
1535 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1667 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1536 | } |
1668 | } |
1537 | |
1669 | |
1538 | /* now rebuild the heap */ |
1670 | /* now rebuild the heap, this for the 2-heap, inefficient for the 4-heap, but correct */ |
1539 | for (i = periodiccnt >> 1; i--; ) |
1671 | for (i = periodiccnt >> 1; --i; ) |
1540 | downheap (periodics, periodiccnt, i); |
1672 | downheap (periodics, periodiccnt, i + HEAP0); |
1541 | } |
|
|
1542 | #endif |
|
|
1543 | |
|
|
1544 | #if EV_IDLE_ENABLE |
|
|
1545 | void inline_size |
|
|
1546 | idle_reify (EV_P) |
|
|
1547 | { |
|
|
1548 | if (expect_false (idleall)) |
|
|
1549 | { |
|
|
1550 | int pri; |
|
|
1551 | |
|
|
1552 | for (pri = NUMPRI; pri--; ) |
|
|
1553 | { |
|
|
1554 | if (pendingcnt [pri]) |
|
|
1555 | break; |
|
|
1556 | |
|
|
1557 | if (idlecnt [pri]) |
|
|
1558 | { |
|
|
1559 | queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE); |
|
|
1560 | break; |
|
|
1561 | } |
|
|
1562 | } |
|
|
1563 | } |
|
|
1564 | } |
1673 | } |
1565 | #endif |
1674 | #endif |
1566 | |
1675 | |
1567 | void inline_speed |
1676 | void inline_speed |
1568 | time_update (EV_P_ ev_tstamp max_block) |
1677 | time_update (EV_P_ ev_tstamp max_block) |
… | |
… | |
1597 | */ |
1706 | */ |
1598 | for (i = 4; --i; ) |
1707 | for (i = 4; --i; ) |
1599 | { |
1708 | { |
1600 | rtmn_diff = ev_rt_now - mn_now; |
1709 | rtmn_diff = ev_rt_now - mn_now; |
1601 | |
1710 | |
1602 | if (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP) |
1711 | if (expect_true (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP)) |
1603 | return; /* all is well */ |
1712 | return; /* all is well */ |
1604 | |
1713 | |
1605 | ev_rt_now = ev_time (); |
1714 | ev_rt_now = ev_time (); |
1606 | mn_now = get_clock (); |
1715 | mn_now = get_clock (); |
1607 | now_floor = mn_now; |
1716 | now_floor = mn_now; |
… | |
… | |
1622 | { |
1731 | { |
1623 | #if EV_PERIODIC_ENABLE |
1732 | #if EV_PERIODIC_ENABLE |
1624 | periodics_reschedule (EV_A); |
1733 | periodics_reschedule (EV_A); |
1625 | #endif |
1734 | #endif |
1626 | /* adjust timers. this is easy, as the offset is the same for all of them */ |
1735 | /* adjust timers. this is easy, as the offset is the same for all of them */ |
1627 | for (i = 1; i <= timercnt; ++i) |
1736 | for (i = 0; i < timercnt; ++i) |
1628 | ev_at (timers [i]) += ev_rt_now - mn_now; |
1737 | { |
|
|
1738 | ANHE *he = timers + i + HEAP0; |
|
|
1739 | ANHE_w (*he)->at += ev_rt_now - mn_now; |
|
|
1740 | ANHE_at_set (*he); |
|
|
1741 | } |
1629 | } |
1742 | } |
1630 | |
1743 | |
1631 | mn_now = ev_rt_now; |
1744 | mn_now = ev_rt_now; |
1632 | } |
1745 | } |
1633 | } |
1746 | } |
… | |
… | |
1703 | |
1816 | |
1704 | waittime = MAX_BLOCKTIME; |
1817 | waittime = MAX_BLOCKTIME; |
1705 | |
1818 | |
1706 | if (timercnt) |
1819 | if (timercnt) |
1707 | { |
1820 | { |
1708 | ev_tstamp to = ev_at (timers [1]) - mn_now + backend_fudge; |
1821 | ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now + backend_fudge; |
1709 | if (waittime > to) waittime = to; |
1822 | if (waittime > to) waittime = to; |
1710 | } |
1823 | } |
1711 | |
1824 | |
1712 | #if EV_PERIODIC_ENABLE |
1825 | #if EV_PERIODIC_ENABLE |
1713 | if (periodiccnt) |
1826 | if (periodiccnt) |
1714 | { |
1827 | { |
1715 | ev_tstamp to = ev_at (periodics [1]) - ev_rt_now + backend_fudge; |
1828 | ev_tstamp to = ANHE_at (periodics [HEAP0]) - ev_rt_now + backend_fudge; |
1716 | if (waittime > to) waittime = to; |
1829 | if (waittime > to) waittime = to; |
1717 | } |
1830 | } |
1718 | #endif |
1831 | #endif |
1719 | |
1832 | |
1720 | if (expect_false (waittime < timeout_blocktime)) |
1833 | if (expect_false (waittime < timeout_blocktime)) |
… | |
… | |
1890 | |
2003 | |
1891 | ev_at (w) += mn_now; |
2004 | ev_at (w) += mn_now; |
1892 | |
2005 | |
1893 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
2006 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1894 | |
2007 | |
1895 | ev_start (EV_A_ (W)w, ++timercnt); |
2008 | ev_start (EV_A_ (W)w, ++timercnt + HEAP0 - 1); |
1896 | array_needsize (WT, timers, timermax, timercnt + 1, EMPTY2); |
2009 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); |
1897 | timers [timercnt] = (WT)w; |
2010 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
|
|
2011 | ANHE_at_set (timers [ev_active (w)]); |
1898 | upheap (timers, timercnt); |
2012 | upheap (timers, ev_active (w)); |
1899 | |
2013 | |
1900 | /*assert (("internal timer heap corruption", timers [ev_active (w)] == w));*/ |
2014 | /*assert (("internal timer heap corruption", timers [ev_active (w)] == w));*/ |
1901 | } |
2015 | } |
1902 | |
2016 | |
1903 | void noinline |
2017 | void noinline |
… | |
… | |
1908 | return; |
2022 | return; |
1909 | |
2023 | |
1910 | { |
2024 | { |
1911 | int active = ev_active (w); |
2025 | int active = ev_active (w); |
1912 | |
2026 | |
1913 | assert (("internal timer heap corruption", timers [active] == (WT)w)); |
2027 | assert (("internal timer heap corruption", ANHE_w (timers [active]) == (WT)w)); |
1914 | |
2028 | |
1915 | if (expect_true (active < timercnt)) |
2029 | if (expect_true (active < timercnt + HEAP0 - 1)) |
1916 | { |
2030 | { |
1917 | timers [active] = timers [timercnt]; |
2031 | timers [active] = timers [timercnt + HEAP0 - 1]; |
1918 | adjustheap (timers, timercnt, active); |
2032 | adjustheap (timers, timercnt, active); |
1919 | } |
2033 | } |
1920 | |
2034 | |
1921 | --timercnt; |
2035 | --timercnt; |
1922 | } |
2036 | } |
… | |
… | |
1932 | if (ev_is_active (w)) |
2046 | if (ev_is_active (w)) |
1933 | { |
2047 | { |
1934 | if (w->repeat) |
2048 | if (w->repeat) |
1935 | { |
2049 | { |
1936 | ev_at (w) = mn_now + w->repeat; |
2050 | ev_at (w) = mn_now + w->repeat; |
|
|
2051 | ANHE_at_set (timers [ev_active (w)]); |
1937 | adjustheap (timers, timercnt, ev_active (w)); |
2052 | adjustheap (timers, timercnt, ev_active (w)); |
1938 | } |
2053 | } |
1939 | else |
2054 | else |
1940 | ev_timer_stop (EV_A_ w); |
2055 | ev_timer_stop (EV_A_ w); |
1941 | } |
2056 | } |
… | |
… | |
1962 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
2077 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1963 | } |
2078 | } |
1964 | else |
2079 | else |
1965 | ev_at (w) = w->offset; |
2080 | ev_at (w) = w->offset; |
1966 | |
2081 | |
1967 | ev_start (EV_A_ (W)w, ++periodiccnt); |
2082 | ev_start (EV_A_ (W)w, ++periodiccnt + HEAP0 - 1); |
1968 | array_needsize (WT, periodics, periodicmax, periodiccnt + 1, EMPTY2); |
2083 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); |
1969 | periodics [periodiccnt] = (WT)w; |
2084 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
1970 | upheap (periodics, periodiccnt); |
2085 | upheap (periodics, ev_active (w)); |
1971 | |
2086 | |
1972 | /*assert (("internal periodic heap corruption", periodics [ev_active (w)] == w));*/ |
2087 | /*assert (("internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
1973 | } |
2088 | } |
1974 | |
2089 | |
1975 | void noinline |
2090 | void noinline |
1976 | ev_periodic_stop (EV_P_ ev_periodic *w) |
2091 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1977 | { |
2092 | { |
… | |
… | |
1980 | return; |
2095 | return; |
1981 | |
2096 | |
1982 | { |
2097 | { |
1983 | int active = ev_active (w); |
2098 | int active = ev_active (w); |
1984 | |
2099 | |
1985 | assert (("internal periodic heap corruption", periodics [active] == (WT)w)); |
2100 | assert (("internal periodic heap corruption", ANHE_w (periodics [active]) == (WT)w)); |
1986 | |
2101 | |
1987 | if (expect_true (active < periodiccnt)) |
2102 | if (expect_true (active < periodiccnt + HEAP0 - 1)) |
1988 | { |
2103 | { |
1989 | periodics [active] = periodics [periodiccnt]; |
2104 | periodics [active] = periodics [periodiccnt + HEAP0 - 1]; |
1990 | adjustheap (periodics, periodiccnt, active); |
2105 | adjustheap (periodics, periodiccnt, active); |
1991 | } |
2106 | } |
1992 | |
2107 | |
1993 | --periodiccnt; |
2108 | --periodiccnt; |
1994 | } |
2109 | } |
… | |
… | |
2114 | if (w->wd < 0) |
2229 | if (w->wd < 0) |
2115 | { |
2230 | { |
2116 | ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */ |
2231 | ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */ |
2117 | |
2232 | |
2118 | /* monitor some parent directory for speedup hints */ |
2233 | /* monitor some parent directory for speedup hints */ |
|
|
2234 | /* note that exceeding the hardcoded limit is not a correctness issue, */ |
|
|
2235 | /* but an efficiency issue only */ |
2119 | if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) |
2236 | if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) |
2120 | { |
2237 | { |
2121 | char path [4096]; |
2238 | char path [4096]; |
2122 | strcpy (path, w->path); |
2239 | strcpy (path, w->path); |
2123 | |
2240 | |