… | |
… | |
418 | } |
418 | } |
419 | |
419 | |
420 | return ncur; |
420 | return ncur; |
421 | } |
421 | } |
422 | |
422 | |
423 | inline_speed void * |
423 | static noinline void * |
424 | array_realloc (int elem, void *base, int *cur, int cnt) |
424 | array_realloc (int elem, void *base, int *cur, int cnt) |
425 | { |
425 | { |
426 | *cur = array_nextsize (elem, *cur, cnt); |
426 | *cur = array_nextsize (elem, *cur, cnt); |
427 | return ev_realloc (base, elem * *cur); |
427 | return ev_realloc (base, elem * *cur); |
428 | } |
428 | } |
… | |
… | |
453 | |
453 | |
454 | void noinline |
454 | void noinline |
455 | ev_feed_event (EV_P_ void *w, int revents) |
455 | ev_feed_event (EV_P_ void *w, int revents) |
456 | { |
456 | { |
457 | W w_ = (W)w; |
457 | W w_ = (W)w; |
|
|
458 | int pri = ABSPRI (w_); |
458 | |
459 | |
459 | if (expect_false (w_->pending)) |
460 | if (expect_false (w_->pending)) |
|
|
461 | pendings [pri][w_->pending - 1].events |= revents; |
|
|
462 | else |
460 | { |
463 | { |
|
|
464 | w_->pending = ++pendingcnt [pri]; |
|
|
465 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
|
|
466 | pendings [pri][w_->pending - 1].w = w_; |
461 | pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; |
467 | pendings [pri][w_->pending - 1].events = revents; |
462 | return; |
|
|
463 | } |
468 | } |
464 | |
|
|
465 | w_->pending = ++pendingcnt [ABSPRI (w_)]; |
|
|
466 | array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); |
|
|
467 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
|
|
468 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
|
|
469 | } |
469 | } |
470 | |
470 | |
471 | void inline_size |
471 | void inline_size |
472 | queue_events (EV_P_ W *events, int eventcnt, int type) |
472 | queue_events (EV_P_ W *events, int eventcnt, int type) |
473 | { |
473 | { |
… | |
… | |
749 | for (signum = signalmax; signum--; ) |
749 | for (signum = signalmax; signum--; ) |
750 | if (signals [signum].gotsig) |
750 | if (signals [signum].gotsig) |
751 | ev_feed_signal_event (EV_A_ signum + 1); |
751 | ev_feed_signal_event (EV_A_ signum + 1); |
752 | } |
752 | } |
753 | |
753 | |
754 | void inline_size |
754 | void inline_speed |
755 | fd_intern (int fd) |
755 | fd_intern (int fd) |
756 | { |
756 | { |
757 | #ifdef _WIN32 |
757 | #ifdef _WIN32 |
758 | int arg = 1; |
758 | int arg = 1; |
759 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
759 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
… | |
… | |
1231 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1231 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1232 | |
1232 | |
1233 | /* first reschedule or stop timer */ |
1233 | /* first reschedule or stop timer */ |
1234 | if (w->reschedule_cb) |
1234 | if (w->reschedule_cb) |
1235 | { |
1235 | { |
1236 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001); |
1236 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001220703125 /* 1/8192 */); |
1237 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); |
1237 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); |
1238 | downheap ((WT *)periodics, periodiccnt, 0); |
1238 | downheap ((WT *)periodics, periodiccnt, 0); |
1239 | } |
1239 | } |
1240 | else if (w->interval) |
1240 | else if (w->interval) |
1241 | { |
1241 | { |
1242 | ((WT)w)->at += floor ((ev_rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; |
1242 | ((WT)w)->at = w->offset + floor ((ev_rt_now - w->offset) / w->interval + 1.) * w->interval; |
1243 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now)); |
1243 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now)); |
1244 | downheap ((WT *)periodics, periodiccnt, 0); |
1244 | downheap ((WT *)periodics, periodiccnt, 0); |
1245 | } |
1245 | } |
1246 | else |
1246 | else |
1247 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1247 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
… | |
… | |
1261 | ev_periodic *w = periodics [i]; |
1261 | ev_periodic *w = periodics [i]; |
1262 | |
1262 | |
1263 | if (w->reschedule_cb) |
1263 | if (w->reschedule_cb) |
1264 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1264 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1265 | else if (w->interval) |
1265 | else if (w->interval) |
1266 | ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1266 | ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1267 | } |
1267 | } |
1268 | |
1268 | |
1269 | /* now rebuild the heap */ |
1269 | /* now rebuild the heap */ |
1270 | for (i = periodiccnt >> 1; i--; ) |
1270 | for (i = periodiccnt >> 1; i--; ) |
1271 | downheap ((WT *)periodics, periodiccnt, i); |
1271 | downheap ((WT *)periodics, periodiccnt, i); |
… | |
… | |
1546 | ev_clear_pending (EV_P_ void *w) |
1546 | ev_clear_pending (EV_P_ void *w) |
1547 | { |
1547 | { |
1548 | W w_ = (W)w; |
1548 | W w_ = (W)w; |
1549 | int pending = w_->pending; |
1549 | int pending = w_->pending; |
1550 | |
1550 | |
1551 | if (!pending) |
1551 | if (expect_true (pending)) |
|
|
1552 | { |
|
|
1553 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
|
|
1554 | w_->pending = 0; |
|
|
1555 | p->w = 0; |
|
|
1556 | return p->events; |
|
|
1557 | } |
|
|
1558 | else |
1552 | return 0; |
1559 | return 0; |
1553 | |
|
|
1554 | w_->pending = 0; |
|
|
1555 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
|
|
1556 | p->w = 0; |
|
|
1557 | |
|
|
1558 | return p->events; |
|
|
1559 | } |
1560 | } |
1560 | |
1561 | |
1561 | void inline_size |
1562 | void inline_size |
1562 | pri_adjust (EV_P_ W w) |
1563 | pri_adjust (EV_P_ W w) |
1563 | { |
1564 | { |
… | |
… | |
1582 | w->active = 0; |
1583 | w->active = 0; |
1583 | } |
1584 | } |
1584 | |
1585 | |
1585 | /*****************************************************************************/ |
1586 | /*****************************************************************************/ |
1586 | |
1587 | |
1587 | void |
1588 | void noinline |
1588 | ev_io_start (EV_P_ ev_io *w) |
1589 | ev_io_start (EV_P_ ev_io *w) |
1589 | { |
1590 | { |
1590 | int fd = w->fd; |
1591 | int fd = w->fd; |
1591 | |
1592 | |
1592 | if (expect_false (ev_is_active (w))) |
1593 | if (expect_false (ev_is_active (w))) |
… | |
… | |
1599 | wlist_add ((WL *)&anfds[fd].head, (WL)w); |
1600 | wlist_add ((WL *)&anfds[fd].head, (WL)w); |
1600 | |
1601 | |
1601 | fd_change (EV_A_ fd); |
1602 | fd_change (EV_A_ fd); |
1602 | } |
1603 | } |
1603 | |
1604 | |
1604 | void |
1605 | void noinline |
1605 | ev_io_stop (EV_P_ ev_io *w) |
1606 | ev_io_stop (EV_P_ ev_io *w) |
1606 | { |
1607 | { |
1607 | clear_pending (EV_A_ (W)w); |
1608 | clear_pending (EV_A_ (W)w); |
1608 | if (expect_false (!ev_is_active (w))) |
1609 | if (expect_false (!ev_is_active (w))) |
1609 | return; |
1610 | return; |
… | |
… | |
1614 | ev_stop (EV_A_ (W)w); |
1615 | ev_stop (EV_A_ (W)w); |
1615 | |
1616 | |
1616 | fd_change (EV_A_ w->fd); |
1617 | fd_change (EV_A_ w->fd); |
1617 | } |
1618 | } |
1618 | |
1619 | |
1619 | void |
1620 | void noinline |
1620 | ev_timer_start (EV_P_ ev_timer *w) |
1621 | ev_timer_start (EV_P_ ev_timer *w) |
1621 | { |
1622 | { |
1622 | if (expect_false (ev_is_active (w))) |
1623 | if (expect_false (ev_is_active (w))) |
1623 | return; |
1624 | return; |
1624 | |
1625 | |
… | |
… | |
1632 | upheap ((WT *)timers, timercnt - 1); |
1633 | upheap ((WT *)timers, timercnt - 1); |
1633 | |
1634 | |
1634 | /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ |
1635 | /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ |
1635 | } |
1636 | } |
1636 | |
1637 | |
1637 | void |
1638 | void noinline |
1638 | ev_timer_stop (EV_P_ ev_timer *w) |
1639 | ev_timer_stop (EV_P_ ev_timer *w) |
1639 | { |
1640 | { |
1640 | clear_pending (EV_A_ (W)w); |
1641 | clear_pending (EV_A_ (W)w); |
1641 | if (expect_false (!ev_is_active (w))) |
1642 | if (expect_false (!ev_is_active (w))) |
1642 | return; |
1643 | return; |
… | |
… | |
1656 | ((WT)w)->at -= mn_now; |
1657 | ((WT)w)->at -= mn_now; |
1657 | |
1658 | |
1658 | ev_stop (EV_A_ (W)w); |
1659 | ev_stop (EV_A_ (W)w); |
1659 | } |
1660 | } |
1660 | |
1661 | |
1661 | void |
1662 | void noinline |
1662 | ev_timer_again (EV_P_ ev_timer *w) |
1663 | ev_timer_again (EV_P_ ev_timer *w) |
1663 | { |
1664 | { |
1664 | if (ev_is_active (w)) |
1665 | if (ev_is_active (w)) |
1665 | { |
1666 | { |
1666 | if (w->repeat) |
1667 | if (w->repeat) |
… | |
… | |
1677 | ev_timer_start (EV_A_ w); |
1678 | ev_timer_start (EV_A_ w); |
1678 | } |
1679 | } |
1679 | } |
1680 | } |
1680 | |
1681 | |
1681 | #if EV_PERIODIC_ENABLE |
1682 | #if EV_PERIODIC_ENABLE |
1682 | void |
1683 | void noinline |
1683 | ev_periodic_start (EV_P_ ev_periodic *w) |
1684 | ev_periodic_start (EV_P_ ev_periodic *w) |
1684 | { |
1685 | { |
1685 | if (expect_false (ev_is_active (w))) |
1686 | if (expect_false (ev_is_active (w))) |
1686 | return; |
1687 | return; |
1687 | |
1688 | |
… | |
… | |
1689 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1690 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1690 | else if (w->interval) |
1691 | else if (w->interval) |
1691 | { |
1692 | { |
1692 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1693 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1693 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1694 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1694 | ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1695 | ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1695 | } |
1696 | } |
|
|
1697 | else |
|
|
1698 | ((WT)w)->at = w->offset; |
1696 | |
1699 | |
1697 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1700 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1698 | array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); |
1701 | array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); |
1699 | periodics [periodiccnt - 1] = w; |
1702 | periodics [periodiccnt - 1] = w; |
1700 | upheap ((WT *)periodics, periodiccnt - 1); |
1703 | upheap ((WT *)periodics, periodiccnt - 1); |
1701 | |
1704 | |
1702 | /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ |
1705 | /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ |
1703 | } |
1706 | } |
1704 | |
1707 | |
1705 | void |
1708 | void noinline |
1706 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1709 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1707 | { |
1710 | { |
1708 | clear_pending (EV_A_ (W)w); |
1711 | clear_pending (EV_A_ (W)w); |
1709 | if (expect_false (!ev_is_active (w))) |
1712 | if (expect_false (!ev_is_active (w))) |
1710 | return; |
1713 | return; |
… | |
… | |
1722 | } |
1725 | } |
1723 | |
1726 | |
1724 | ev_stop (EV_A_ (W)w); |
1727 | ev_stop (EV_A_ (W)w); |
1725 | } |
1728 | } |
1726 | |
1729 | |
1727 | void |
1730 | void noinline |
1728 | ev_periodic_again (EV_P_ ev_periodic *w) |
1731 | ev_periodic_again (EV_P_ ev_periodic *w) |
1729 | { |
1732 | { |
1730 | /* TODO: use adjustheap and recalculation */ |
1733 | /* TODO: use adjustheap and recalculation */ |
1731 | ev_periodic_stop (EV_A_ w); |
1734 | ev_periodic_stop (EV_A_ w); |
1732 | ev_periodic_start (EV_A_ w); |
1735 | ev_periodic_start (EV_A_ w); |
… | |
… | |
1735 | |
1738 | |
1736 | #ifndef SA_RESTART |
1739 | #ifndef SA_RESTART |
1737 | # define SA_RESTART 0 |
1740 | # define SA_RESTART 0 |
1738 | #endif |
1741 | #endif |
1739 | |
1742 | |
1740 | void |
1743 | void noinline |
1741 | ev_signal_start (EV_P_ ev_signal *w) |
1744 | ev_signal_start (EV_P_ ev_signal *w) |
1742 | { |
1745 | { |
1743 | #if EV_MULTIPLICITY |
1746 | #if EV_MULTIPLICITY |
1744 | assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1747 | assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1745 | #endif |
1748 | #endif |
… | |
… | |
1764 | sigaction (w->signum, &sa, 0); |
1767 | sigaction (w->signum, &sa, 0); |
1765 | #endif |
1768 | #endif |
1766 | } |
1769 | } |
1767 | } |
1770 | } |
1768 | |
1771 | |
1769 | void |
1772 | void noinline |
1770 | ev_signal_stop (EV_P_ ev_signal *w) |
1773 | ev_signal_stop (EV_P_ ev_signal *w) |
1771 | { |
1774 | { |
1772 | clear_pending (EV_A_ (W)w); |
1775 | clear_pending (EV_A_ (W)w); |
1773 | if (expect_false (!ev_is_active (w))) |
1776 | if (expect_false (!ev_is_active (w))) |
1774 | return; |
1777 | return; |