… | |
… | |
241 | |
241 | |
242 | #define expect_false(expr) expect ((expr) != 0, 0) |
242 | #define expect_false(expr) expect ((expr) != 0, 0) |
243 | #define expect_true(expr) expect ((expr) != 0, 1) |
243 | #define expect_true(expr) expect ((expr) != 0, 1) |
244 | |
244 | |
245 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
245 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
246 | #define ABSPRI(w) ((w)->priority - EV_MINPRI) |
246 | #define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
247 | |
247 | |
248 | #define EMPTY0 /* required for microsofts broken pseudo-c compiler */ |
248 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
249 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
249 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
250 | |
250 | |
251 | typedef ev_watcher *W; |
251 | typedef ev_watcher *W; |
252 | typedef ev_watcher_list *WL; |
252 | typedef ev_watcher_list *WL; |
253 | typedef ev_watcher_time *WT; |
253 | typedef ev_watcher_time *WT; |
… | |
… | |
507 | } |
507 | } |
508 | |
508 | |
509 | void |
509 | void |
510 | ev_feed_fd_event (EV_P_ int fd, int revents) |
510 | ev_feed_fd_event (EV_P_ int fd, int revents) |
511 | { |
511 | { |
|
|
512 | if (fd >= 0 && fd < anfdmax) |
512 | fd_event (EV_A_ fd, revents); |
513 | fd_event (EV_A_ fd, revents); |
513 | } |
514 | } |
514 | |
515 | |
515 | void inline_size |
516 | void inline_size |
516 | fd_reify (EV_P) |
517 | fd_reify (EV_P) |
517 | { |
518 | { |
… | |
… | |
786 | ev_child *w; |
787 | ev_child *w; |
787 | |
788 | |
788 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
789 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
789 | if (w->pid == pid || !w->pid) |
790 | if (w->pid == pid || !w->pid) |
790 | { |
791 | { |
791 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
792 | ev_set_priority (w, ev_priority (sw)); /* need to do it *now* */ |
792 | w->rpid = pid; |
793 | w->rpid = pid; |
793 | w->rstatus = status; |
794 | w->rstatus = status; |
794 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
795 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
795 | } |
796 | } |
796 | } |
797 | } |
797 | |
798 | |
798 | #ifndef WCONTINUED |
799 | #ifndef WCONTINUED |
… | |
… | |
1003 | #if EV_USE_SELECT |
1004 | #if EV_USE_SELECT |
1004 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
1005 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
1005 | #endif |
1006 | #endif |
1006 | |
1007 | |
1007 | for (i = NUMPRI; i--; ) |
1008 | for (i = NUMPRI; i--; ) |
|
|
1009 | { |
1008 | array_free (pending, [i]); |
1010 | array_free (pending, [i]); |
|
|
1011 | #if EV_IDLE_ENABLE |
|
|
1012 | array_free (idle, [i]); |
|
|
1013 | #endif |
|
|
1014 | } |
1009 | |
1015 | |
1010 | /* have to use the microsoft-never-gets-it-right macro */ |
1016 | /* have to use the microsoft-never-gets-it-right macro */ |
1011 | array_free (fdchange, EMPTY0); |
1017 | array_free (fdchange, EMPTY); |
1012 | array_free (timer, EMPTY0); |
1018 | array_free (timer, EMPTY); |
1013 | #if EV_PERIODIC_ENABLE |
1019 | #if EV_PERIODIC_ENABLE |
1014 | array_free (periodic, EMPTY0); |
1020 | array_free (periodic, EMPTY); |
1015 | #endif |
1021 | #endif |
1016 | array_free (idle, EMPTY0); |
|
|
1017 | array_free (prepare, EMPTY0); |
1022 | array_free (prepare, EMPTY); |
1018 | array_free (check, EMPTY0); |
1023 | array_free (check, EMPTY); |
1019 | |
1024 | |
1020 | backend = 0; |
1025 | backend = 0; |
1021 | } |
1026 | } |
1022 | |
1027 | |
1023 | void inline_size infy_fork (EV_P); |
1028 | void inline_size infy_fork (EV_P); |
… | |
… | |
1159 | postfork = 1; |
1164 | postfork = 1; |
1160 | } |
1165 | } |
1161 | |
1166 | |
1162 | /*****************************************************************************/ |
1167 | /*****************************************************************************/ |
1163 | |
1168 | |
1164 | int inline_size |
1169 | void |
1165 | any_pending (EV_P) |
1170 | ev_invoke (EV_P_ void *w, int revents) |
1166 | { |
1171 | { |
1167 | int pri; |
1172 | EV_CB_INVOKE ((W)w, revents); |
1168 | |
|
|
1169 | for (pri = NUMPRI; pri--; ) |
|
|
1170 | if (pendingcnt [pri]) |
|
|
1171 | return 1; |
|
|
1172 | |
|
|
1173 | return 0; |
|
|
1174 | } |
1173 | } |
1175 | |
1174 | |
1176 | void inline_speed |
1175 | void inline_speed |
1177 | call_pending (EV_P) |
1176 | call_pending (EV_P) |
1178 | { |
1177 | { |
… | |
… | |
1270 | for (i = periodiccnt >> 1; i--; ) |
1269 | for (i = periodiccnt >> 1; i--; ) |
1271 | downheap ((WT *)periodics, periodiccnt, i); |
1270 | downheap ((WT *)periodics, periodiccnt, i); |
1272 | } |
1271 | } |
1273 | #endif |
1272 | #endif |
1274 | |
1273 | |
|
|
1274 | #if EV_IDLE_ENABLE |
|
|
1275 | void inline_size |
|
|
1276 | idle_reify (EV_P) |
|
|
1277 | { |
|
|
1278 | if (expect_false (idleall)) |
|
|
1279 | { |
|
|
1280 | int pri; |
|
|
1281 | |
|
|
1282 | for (pri = NUMPRI; pri--; ) |
|
|
1283 | { |
|
|
1284 | if (pendingcnt [pri]) |
|
|
1285 | break; |
|
|
1286 | |
|
|
1287 | if (idlecnt [pri]) |
|
|
1288 | { |
|
|
1289 | queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE); |
|
|
1290 | break; |
|
|
1291 | } |
|
|
1292 | } |
|
|
1293 | } |
|
|
1294 | } |
|
|
1295 | #endif |
|
|
1296 | |
1275 | int inline_size |
1297 | int inline_size |
1276 | time_update_monotonic (EV_P) |
1298 | time_update_monotonic (EV_P) |
1277 | { |
1299 | { |
1278 | mn_now = get_clock (); |
1300 | mn_now = get_clock (); |
1279 | |
1301 | |
… | |
… | |
1412 | |
1434 | |
1413 | /* calculate blocking time */ |
1435 | /* calculate blocking time */ |
1414 | { |
1436 | { |
1415 | ev_tstamp block; |
1437 | ev_tstamp block; |
1416 | |
1438 | |
1417 | if (expect_false (flags & EVLOOP_NONBLOCK || idlecnt || !activecnt)) |
1439 | if (expect_false (flags & EVLOOP_NONBLOCK || idleall || !activecnt)) |
1418 | block = 0.; /* do not block at all */ |
1440 | block = 0.; /* do not block at all */ |
1419 | else |
1441 | else |
1420 | { |
1442 | { |
1421 | /* update time to cancel out callback processing overhead */ |
1443 | /* update time to cancel out callback processing overhead */ |
1422 | #if EV_USE_MONOTONIC |
1444 | #if EV_USE_MONOTONIC |
… | |
… | |
1459 | timers_reify (EV_A); /* relative timers called last */ |
1481 | timers_reify (EV_A); /* relative timers called last */ |
1460 | #if EV_PERIODIC_ENABLE |
1482 | #if EV_PERIODIC_ENABLE |
1461 | periodics_reify (EV_A); /* absolute timers called first */ |
1483 | periodics_reify (EV_A); /* absolute timers called first */ |
1462 | #endif |
1484 | #endif |
1463 | |
1485 | |
|
|
1486 | #if EV_IDLE_ENABLE |
1464 | /* queue idle watchers unless other events are pending */ |
1487 | /* queue idle watchers unless other events are pending */ |
1465 | if (idlecnt && !any_pending (EV_A)) |
1488 | idle_reify (EV_A); |
1466 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1489 | #endif |
1467 | |
1490 | |
1468 | /* queue check watchers, to be executed first */ |
1491 | /* queue check watchers, to be executed first */ |
1469 | if (expect_false (checkcnt)) |
1492 | if (expect_false (checkcnt)) |
1470 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1493 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1471 | |
1494 | |
… | |
… | |
1507 | head = &(*head)->next; |
1530 | head = &(*head)->next; |
1508 | } |
1531 | } |
1509 | } |
1532 | } |
1510 | |
1533 | |
1511 | void inline_speed |
1534 | void inline_speed |
1512 | ev_clear_pending (EV_P_ W w) |
1535 | clear_pending (EV_P_ W w) |
1513 | { |
1536 | { |
1514 | if (w->pending) |
1537 | if (w->pending) |
1515 | { |
1538 | { |
1516 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
1539 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
1517 | w->pending = 0; |
1540 | w->pending = 0; |
1518 | } |
1541 | } |
1519 | } |
1542 | } |
1520 | |
1543 | |
|
|
1544 | int |
|
|
1545 | ev_clear_pending (EV_P_ void *w) |
|
|
1546 | { |
|
|
1547 | W w_ = (W)w; |
|
|
1548 | int pending = w_->pending; |
|
|
1549 | |
|
|
1550 | if (!pending) |
|
|
1551 | return 0; |
|
|
1552 | |
|
|
1553 | w_->pending = 0; |
|
|
1554 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
|
|
1555 | p->w = 0; |
|
|
1556 | |
|
|
1557 | return p->events; |
|
|
1558 | } |
|
|
1559 | |
|
|
1560 | void inline_size |
|
|
1561 | pri_adjust (EV_P_ W w) |
|
|
1562 | { |
|
|
1563 | int pri = w->priority; |
|
|
1564 | pri = pri < EV_MINPRI ? EV_MINPRI : pri; |
|
|
1565 | pri = pri > EV_MAXPRI ? EV_MAXPRI : pri; |
|
|
1566 | w->priority = pri; |
|
|
1567 | } |
|
|
1568 | |
1521 | void inline_speed |
1569 | void inline_speed |
1522 | ev_start (EV_P_ W w, int active) |
1570 | ev_start (EV_P_ W w, int active) |
1523 | { |
1571 | { |
1524 | if (w->priority < EV_MINPRI) w->priority = EV_MINPRI; |
1572 | pri_adjust (EV_A_ w); |
1525 | if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI; |
|
|
1526 | |
|
|
1527 | w->active = active; |
1573 | w->active = active; |
1528 | ev_ref (EV_A); |
1574 | ev_ref (EV_A); |
1529 | } |
1575 | } |
1530 | |
1576 | |
1531 | void inline_size |
1577 | void inline_size |
… | |
… | |
1555 | } |
1601 | } |
1556 | |
1602 | |
1557 | void |
1603 | void |
1558 | ev_io_stop (EV_P_ ev_io *w) |
1604 | ev_io_stop (EV_P_ ev_io *w) |
1559 | { |
1605 | { |
1560 | ev_clear_pending (EV_A_ (W)w); |
1606 | clear_pending (EV_A_ (W)w); |
1561 | if (expect_false (!ev_is_active (w))) |
1607 | if (expect_false (!ev_is_active (w))) |
1562 | return; |
1608 | return; |
1563 | |
1609 | |
1564 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1610 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1565 | |
1611 | |
… | |
… | |
1588 | } |
1634 | } |
1589 | |
1635 | |
1590 | void |
1636 | void |
1591 | ev_timer_stop (EV_P_ ev_timer *w) |
1637 | ev_timer_stop (EV_P_ ev_timer *w) |
1592 | { |
1638 | { |
1593 | ev_clear_pending (EV_A_ (W)w); |
1639 | clear_pending (EV_A_ (W)w); |
1594 | if (expect_false (!ev_is_active (w))) |
1640 | if (expect_false (!ev_is_active (w))) |
1595 | return; |
1641 | return; |
1596 | |
1642 | |
1597 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1643 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1598 | |
1644 | |
… | |
… | |
1656 | } |
1702 | } |
1657 | |
1703 | |
1658 | void |
1704 | void |
1659 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1705 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1660 | { |
1706 | { |
1661 | ev_clear_pending (EV_A_ (W)w); |
1707 | clear_pending (EV_A_ (W)w); |
1662 | if (expect_false (!ev_is_active (w))) |
1708 | if (expect_false (!ev_is_active (w))) |
1663 | return; |
1709 | return; |
1664 | |
1710 | |
1665 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1711 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1666 | |
1712 | |
… | |
… | |
1720 | } |
1766 | } |
1721 | |
1767 | |
1722 | void |
1768 | void |
1723 | ev_signal_stop (EV_P_ ev_signal *w) |
1769 | ev_signal_stop (EV_P_ ev_signal *w) |
1724 | { |
1770 | { |
1725 | ev_clear_pending (EV_A_ (W)w); |
1771 | clear_pending (EV_A_ (W)w); |
1726 | if (expect_false (!ev_is_active (w))) |
1772 | if (expect_false (!ev_is_active (w))) |
1727 | return; |
1773 | return; |
1728 | |
1774 | |
1729 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1775 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1730 | ev_stop (EV_A_ (W)w); |
1776 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1747 | } |
1793 | } |
1748 | |
1794 | |
1749 | void |
1795 | void |
1750 | ev_child_stop (EV_P_ ev_child *w) |
1796 | ev_child_stop (EV_P_ ev_child *w) |
1751 | { |
1797 | { |
1752 | ev_clear_pending (EV_A_ (W)w); |
1798 | clear_pending (EV_A_ (W)w); |
1753 | if (expect_false (!ev_is_active (w))) |
1799 | if (expect_false (!ev_is_active (w))) |
1754 | return; |
1800 | return; |
1755 | |
1801 | |
1756 | wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1802 | wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1757 | ev_stop (EV_A_ (W)w); |
1803 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1993 | } |
2039 | } |
1994 | |
2040 | |
1995 | void |
2041 | void |
1996 | ev_stat_stop (EV_P_ ev_stat *w) |
2042 | ev_stat_stop (EV_P_ ev_stat *w) |
1997 | { |
2043 | { |
1998 | ev_clear_pending (EV_A_ (W)w); |
2044 | clear_pending (EV_A_ (W)w); |
1999 | if (expect_false (!ev_is_active (w))) |
2045 | if (expect_false (!ev_is_active (w))) |
2000 | return; |
2046 | return; |
2001 | |
2047 | |
2002 | #if EV_USE_INOTIFY |
2048 | #if EV_USE_INOTIFY |
2003 | infy_del (EV_A_ w); |
2049 | infy_del (EV_A_ w); |
… | |
… | |
2006 | |
2052 | |
2007 | ev_stop (EV_A_ (W)w); |
2053 | ev_stop (EV_A_ (W)w); |
2008 | } |
2054 | } |
2009 | #endif |
2055 | #endif |
2010 | |
2056 | |
|
|
2057 | #if EV_IDLE_ENABLE |
2011 | void |
2058 | void |
2012 | ev_idle_start (EV_P_ ev_idle *w) |
2059 | ev_idle_start (EV_P_ ev_idle *w) |
2013 | { |
2060 | { |
2014 | if (expect_false (ev_is_active (w))) |
2061 | if (expect_false (ev_is_active (w))) |
2015 | return; |
2062 | return; |
2016 | |
2063 | |
|
|
2064 | pri_adjust (EV_A_ (W)w); |
|
|
2065 | |
|
|
2066 | { |
|
|
2067 | int active = ++idlecnt [ABSPRI (w)]; |
|
|
2068 | |
|
|
2069 | ++idleall; |
2017 | ev_start (EV_A_ (W)w, ++idlecnt); |
2070 | ev_start (EV_A_ (W)w, active); |
|
|
2071 | |
2018 | array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
2072 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
2019 | idles [idlecnt - 1] = w; |
2073 | idles [ABSPRI (w)][active - 1] = w; |
|
|
2074 | } |
2020 | } |
2075 | } |
2021 | |
2076 | |
2022 | void |
2077 | void |
2023 | ev_idle_stop (EV_P_ ev_idle *w) |
2078 | ev_idle_stop (EV_P_ ev_idle *w) |
2024 | { |
2079 | { |
2025 | ev_clear_pending (EV_A_ (W)w); |
2080 | clear_pending (EV_A_ (W)w); |
2026 | if (expect_false (!ev_is_active (w))) |
2081 | if (expect_false (!ev_is_active (w))) |
2027 | return; |
2082 | return; |
2028 | |
2083 | |
2029 | { |
2084 | { |
2030 | int active = ((W)w)->active; |
2085 | int active = ((W)w)->active; |
2031 | idles [active - 1] = idles [--idlecnt]; |
2086 | |
|
|
2087 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
2032 | ((W)idles [active - 1])->active = active; |
2088 | ((W)idles [ABSPRI (w)][active - 1])->active = active; |
|
|
2089 | |
|
|
2090 | ev_stop (EV_A_ (W)w); |
|
|
2091 | --idleall; |
2033 | } |
2092 | } |
2034 | |
|
|
2035 | ev_stop (EV_A_ (W)w); |
|
|
2036 | } |
2093 | } |
|
|
2094 | #endif |
2037 | |
2095 | |
2038 | void |
2096 | void |
2039 | ev_prepare_start (EV_P_ ev_prepare *w) |
2097 | ev_prepare_start (EV_P_ ev_prepare *w) |
2040 | { |
2098 | { |
2041 | if (expect_false (ev_is_active (w))) |
2099 | if (expect_false (ev_is_active (w))) |
… | |
… | |
2047 | } |
2105 | } |
2048 | |
2106 | |
2049 | void |
2107 | void |
2050 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2108 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2051 | { |
2109 | { |
2052 | ev_clear_pending (EV_A_ (W)w); |
2110 | clear_pending (EV_A_ (W)w); |
2053 | if (expect_false (!ev_is_active (w))) |
2111 | if (expect_false (!ev_is_active (w))) |
2054 | return; |
2112 | return; |
2055 | |
2113 | |
2056 | { |
2114 | { |
2057 | int active = ((W)w)->active; |
2115 | int active = ((W)w)->active; |
… | |
… | |
2074 | } |
2132 | } |
2075 | |
2133 | |
2076 | void |
2134 | void |
2077 | ev_check_stop (EV_P_ ev_check *w) |
2135 | ev_check_stop (EV_P_ ev_check *w) |
2078 | { |
2136 | { |
2079 | ev_clear_pending (EV_A_ (W)w); |
2137 | clear_pending (EV_A_ (W)w); |
2080 | if (expect_false (!ev_is_active (w))) |
2138 | if (expect_false (!ev_is_active (w))) |
2081 | return; |
2139 | return; |
2082 | |
2140 | |
2083 | { |
2141 | { |
2084 | int active = ((W)w)->active; |
2142 | int active = ((W)w)->active; |
… | |
… | |
2126 | } |
2184 | } |
2127 | |
2185 | |
2128 | void |
2186 | void |
2129 | ev_embed_stop (EV_P_ ev_embed *w) |
2187 | ev_embed_stop (EV_P_ ev_embed *w) |
2130 | { |
2188 | { |
2131 | ev_clear_pending (EV_A_ (W)w); |
2189 | clear_pending (EV_A_ (W)w); |
2132 | if (expect_false (!ev_is_active (w))) |
2190 | if (expect_false (!ev_is_active (w))) |
2133 | return; |
2191 | return; |
2134 | |
2192 | |
2135 | ev_io_stop (EV_A_ &w->io); |
2193 | ev_io_stop (EV_A_ &w->io); |
2136 | |
2194 | |
… | |
… | |
2151 | } |
2209 | } |
2152 | |
2210 | |
2153 | void |
2211 | void |
2154 | ev_fork_stop (EV_P_ ev_fork *w) |
2212 | ev_fork_stop (EV_P_ ev_fork *w) |
2155 | { |
2213 | { |
2156 | ev_clear_pending (EV_A_ (W)w); |
2214 | clear_pending (EV_A_ (W)w); |
2157 | if (expect_false (!ev_is_active (w))) |
2215 | if (expect_false (!ev_is_active (w))) |
2158 | return; |
2216 | return; |
2159 | |
2217 | |
2160 | { |
2218 | { |
2161 | int active = ((W)w)->active; |
2219 | int active = ((W)w)->active; |