… | |
… | |
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; |
… | |
… | |
786 | ev_child *w; |
786 | ev_child *w; |
787 | |
787 | |
788 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
788 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
789 | if (w->pid == pid || !w->pid) |
789 | if (w->pid == pid || !w->pid) |
790 | { |
790 | { |
791 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
791 | ev_set_priority (w, ev_priority (sw)); /* need to do it *now* */ |
792 | w->rpid = pid; |
792 | w->rpid = pid; |
793 | w->rstatus = status; |
793 | w->rstatus = status; |
794 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
794 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
795 | } |
795 | } |
796 | } |
796 | } |
797 | |
797 | |
798 | #ifndef WCONTINUED |
798 | #ifndef WCONTINUED |
… | |
… | |
1003 | #if EV_USE_SELECT |
1003 | #if EV_USE_SELECT |
1004 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
1004 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
1005 | #endif |
1005 | #endif |
1006 | |
1006 | |
1007 | for (i = NUMPRI; i--; ) |
1007 | for (i = NUMPRI; i--; ) |
|
|
1008 | { |
1008 | array_free (pending, [i]); |
1009 | array_free (pending, [i]); |
|
|
1010 | #if EV_IDLE_ENABLE |
|
|
1011 | array_free (idle, [i]); |
|
|
1012 | #endif |
|
|
1013 | } |
1009 | |
1014 | |
1010 | /* have to use the microsoft-never-gets-it-right macro */ |
1015 | /* have to use the microsoft-never-gets-it-right macro */ |
1011 | array_free (fdchange, EMPTY0); |
1016 | array_free (fdchange, EMPTY); |
1012 | array_free (timer, EMPTY0); |
1017 | array_free (timer, EMPTY); |
1013 | #if EV_PERIODIC_ENABLE |
1018 | #if EV_PERIODIC_ENABLE |
1014 | array_free (periodic, EMPTY0); |
1019 | array_free (periodic, EMPTY); |
1015 | #endif |
1020 | #endif |
1016 | array_free (idle, EMPTY0); |
|
|
1017 | array_free (prepare, EMPTY0); |
1021 | array_free (prepare, EMPTY); |
1018 | array_free (check, EMPTY0); |
1022 | array_free (check, EMPTY); |
1019 | |
1023 | |
1020 | backend = 0; |
1024 | backend = 0; |
1021 | } |
1025 | } |
1022 | |
1026 | |
1023 | void inline_size infy_fork (EV_P); |
1027 | void inline_size infy_fork (EV_P); |
… | |
… | |
1158 | if (backend) |
1162 | if (backend) |
1159 | postfork = 1; |
1163 | postfork = 1; |
1160 | } |
1164 | } |
1161 | |
1165 | |
1162 | /*****************************************************************************/ |
1166 | /*****************************************************************************/ |
1163 | |
|
|
1164 | int inline_size |
|
|
1165 | any_pending (EV_P) |
|
|
1166 | { |
|
|
1167 | int pri; |
|
|
1168 | |
|
|
1169 | for (pri = NUMPRI; pri--; ) |
|
|
1170 | if (pendingcnt [pri]) |
|
|
1171 | return 1; |
|
|
1172 | |
|
|
1173 | return 0; |
|
|
1174 | } |
|
|
1175 | |
1167 | |
1176 | void inline_speed |
1168 | void inline_speed |
1177 | call_pending (EV_P) |
1169 | call_pending (EV_P) |
1178 | { |
1170 | { |
1179 | int pri; |
1171 | int pri; |
… | |
… | |
1270 | for (i = periodiccnt >> 1; i--; ) |
1262 | for (i = periodiccnt >> 1; i--; ) |
1271 | downheap ((WT *)periodics, periodiccnt, i); |
1263 | downheap ((WT *)periodics, periodiccnt, i); |
1272 | } |
1264 | } |
1273 | #endif |
1265 | #endif |
1274 | |
1266 | |
|
|
1267 | #if EV_IDLE_ENABLE |
|
|
1268 | void inline_size |
|
|
1269 | idle_reify (EV_P) |
|
|
1270 | { |
|
|
1271 | if (expect_false (idleall)) |
|
|
1272 | { |
|
|
1273 | int pri; |
|
|
1274 | |
|
|
1275 | for (pri = NUMPRI; pri--; ) |
|
|
1276 | { |
|
|
1277 | if (pendingcnt [pri]) |
|
|
1278 | break; |
|
|
1279 | |
|
|
1280 | if (idlecnt [pri]) |
|
|
1281 | { |
|
|
1282 | queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE); |
|
|
1283 | break; |
|
|
1284 | } |
|
|
1285 | } |
|
|
1286 | } |
|
|
1287 | } |
|
|
1288 | #endif |
|
|
1289 | |
1275 | int inline_size |
1290 | int inline_size |
1276 | time_update_monotonic (EV_P) |
1291 | time_update_monotonic (EV_P) |
1277 | { |
1292 | { |
1278 | mn_now = get_clock (); |
1293 | mn_now = get_clock (); |
1279 | |
1294 | |
… | |
… | |
1412 | |
1427 | |
1413 | /* calculate blocking time */ |
1428 | /* calculate blocking time */ |
1414 | { |
1429 | { |
1415 | ev_tstamp block; |
1430 | ev_tstamp block; |
1416 | |
1431 | |
1417 | if (expect_false (flags & EVLOOP_NONBLOCK || idlecnt || !activecnt)) |
1432 | if (expect_false (flags & EVLOOP_NONBLOCK || idleall || !activecnt)) |
1418 | block = 0.; /* do not block at all */ |
1433 | block = 0.; /* do not block at all */ |
1419 | else |
1434 | else |
1420 | { |
1435 | { |
1421 | /* update time to cancel out callback processing overhead */ |
1436 | /* update time to cancel out callback processing overhead */ |
1422 | #if EV_USE_MONOTONIC |
1437 | #if EV_USE_MONOTONIC |
… | |
… | |
1459 | timers_reify (EV_A); /* relative timers called last */ |
1474 | timers_reify (EV_A); /* relative timers called last */ |
1460 | #if EV_PERIODIC_ENABLE |
1475 | #if EV_PERIODIC_ENABLE |
1461 | periodics_reify (EV_A); /* absolute timers called first */ |
1476 | periodics_reify (EV_A); /* absolute timers called first */ |
1462 | #endif |
1477 | #endif |
1463 | |
1478 | |
|
|
1479 | #if EV_IDLE_ENABLE |
1464 | /* queue idle watchers unless other events are pending */ |
1480 | /* queue idle watchers unless other events are pending */ |
1465 | if (idlecnt && !any_pending (EV_A)) |
1481 | idle_reify (EV_A); |
1466 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1482 | #endif |
1467 | |
1483 | |
1468 | /* queue check watchers, to be executed first */ |
1484 | /* queue check watchers, to be executed first */ |
1469 | if (expect_false (checkcnt)) |
1485 | if (expect_false (checkcnt)) |
1470 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1486 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1471 | |
1487 | |
… | |
… | |
1507 | head = &(*head)->next; |
1523 | head = &(*head)->next; |
1508 | } |
1524 | } |
1509 | } |
1525 | } |
1510 | |
1526 | |
1511 | void inline_speed |
1527 | void inline_speed |
1512 | ev_clear_pending (EV_P_ W w) |
1528 | clear_pending (EV_P_ W w) |
1513 | { |
1529 | { |
1514 | if (w->pending) |
1530 | if (w->pending) |
1515 | { |
1531 | { |
1516 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
1532 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
1517 | w->pending = 0; |
1533 | w->pending = 0; |
1518 | } |
1534 | } |
1519 | } |
1535 | } |
1520 | |
1536 | |
|
|
1537 | int |
|
|
1538 | ev_clear_pending (EV_P_ void *w) |
|
|
1539 | { |
|
|
1540 | W w_ = (W)w; |
|
|
1541 | int pending = w_->pending; |
|
|
1542 | |
|
|
1543 | if (!pending) |
|
|
1544 | return 0; |
|
|
1545 | |
|
|
1546 | w_->pending = 0; |
|
|
1547 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
|
|
1548 | p->w = 0; |
|
|
1549 | |
|
|
1550 | return p->events; |
|
|
1551 | } |
|
|
1552 | |
|
|
1553 | void inline_size |
|
|
1554 | pri_adjust (EV_P_ W w) |
|
|
1555 | { |
|
|
1556 | int pri = w->priority; |
|
|
1557 | pri = pri < EV_MINPRI ? EV_MINPRI : pri; |
|
|
1558 | pri = pri > EV_MAXPRI ? EV_MAXPRI : pri; |
|
|
1559 | w->priority = pri; |
|
|
1560 | } |
|
|
1561 | |
1521 | void inline_speed |
1562 | void inline_speed |
1522 | ev_start (EV_P_ W w, int active) |
1563 | ev_start (EV_P_ W w, int active) |
1523 | { |
1564 | { |
1524 | if (w->priority < EV_MINPRI) w->priority = EV_MINPRI; |
1565 | pri_adjust (EV_A_ w); |
1525 | if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI; |
|
|
1526 | |
|
|
1527 | w->active = active; |
1566 | w->active = active; |
1528 | ev_ref (EV_A); |
1567 | ev_ref (EV_A); |
1529 | } |
1568 | } |
1530 | |
1569 | |
1531 | void inline_size |
1570 | void inline_size |
… | |
… | |
1555 | } |
1594 | } |
1556 | |
1595 | |
1557 | void |
1596 | void |
1558 | ev_io_stop (EV_P_ ev_io *w) |
1597 | ev_io_stop (EV_P_ ev_io *w) |
1559 | { |
1598 | { |
1560 | ev_clear_pending (EV_A_ (W)w); |
1599 | clear_pending (EV_A_ (W)w); |
1561 | if (expect_false (!ev_is_active (w))) |
1600 | if (expect_false (!ev_is_active (w))) |
1562 | return; |
1601 | return; |
1563 | |
1602 | |
1564 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1603 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1565 | |
1604 | |
… | |
… | |
1588 | } |
1627 | } |
1589 | |
1628 | |
1590 | void |
1629 | void |
1591 | ev_timer_stop (EV_P_ ev_timer *w) |
1630 | ev_timer_stop (EV_P_ ev_timer *w) |
1592 | { |
1631 | { |
1593 | ev_clear_pending (EV_A_ (W)w); |
1632 | clear_pending (EV_A_ (W)w); |
1594 | if (expect_false (!ev_is_active (w))) |
1633 | if (expect_false (!ev_is_active (w))) |
1595 | return; |
1634 | return; |
1596 | |
1635 | |
1597 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1636 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1598 | |
1637 | |
… | |
… | |
1656 | } |
1695 | } |
1657 | |
1696 | |
1658 | void |
1697 | void |
1659 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1698 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1660 | { |
1699 | { |
1661 | ev_clear_pending (EV_A_ (W)w); |
1700 | clear_pending (EV_A_ (W)w); |
1662 | if (expect_false (!ev_is_active (w))) |
1701 | if (expect_false (!ev_is_active (w))) |
1663 | return; |
1702 | return; |
1664 | |
1703 | |
1665 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1704 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1666 | |
1705 | |
… | |
… | |
1720 | } |
1759 | } |
1721 | |
1760 | |
1722 | void |
1761 | void |
1723 | ev_signal_stop (EV_P_ ev_signal *w) |
1762 | ev_signal_stop (EV_P_ ev_signal *w) |
1724 | { |
1763 | { |
1725 | ev_clear_pending (EV_A_ (W)w); |
1764 | clear_pending (EV_A_ (W)w); |
1726 | if (expect_false (!ev_is_active (w))) |
1765 | if (expect_false (!ev_is_active (w))) |
1727 | return; |
1766 | return; |
1728 | |
1767 | |
1729 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1768 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1730 | ev_stop (EV_A_ (W)w); |
1769 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1747 | } |
1786 | } |
1748 | |
1787 | |
1749 | void |
1788 | void |
1750 | ev_child_stop (EV_P_ ev_child *w) |
1789 | ev_child_stop (EV_P_ ev_child *w) |
1751 | { |
1790 | { |
1752 | ev_clear_pending (EV_A_ (W)w); |
1791 | clear_pending (EV_A_ (W)w); |
1753 | if (expect_false (!ev_is_active (w))) |
1792 | if (expect_false (!ev_is_active (w))) |
1754 | return; |
1793 | return; |
1755 | |
1794 | |
1756 | wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1795 | wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1757 | ev_stop (EV_A_ (W)w); |
1796 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1993 | } |
2032 | } |
1994 | |
2033 | |
1995 | void |
2034 | void |
1996 | ev_stat_stop (EV_P_ ev_stat *w) |
2035 | ev_stat_stop (EV_P_ ev_stat *w) |
1997 | { |
2036 | { |
1998 | ev_clear_pending (EV_A_ (W)w); |
2037 | clear_pending (EV_A_ (W)w); |
1999 | if (expect_false (!ev_is_active (w))) |
2038 | if (expect_false (!ev_is_active (w))) |
2000 | return; |
2039 | return; |
2001 | |
2040 | |
2002 | #if EV_USE_INOTIFY |
2041 | #if EV_USE_INOTIFY |
2003 | infy_del (EV_A_ w); |
2042 | infy_del (EV_A_ w); |
… | |
… | |
2006 | |
2045 | |
2007 | ev_stop (EV_A_ (W)w); |
2046 | ev_stop (EV_A_ (W)w); |
2008 | } |
2047 | } |
2009 | #endif |
2048 | #endif |
2010 | |
2049 | |
|
|
2050 | #if EV_IDLE_ENABLE |
2011 | void |
2051 | void |
2012 | ev_idle_start (EV_P_ ev_idle *w) |
2052 | ev_idle_start (EV_P_ ev_idle *w) |
2013 | { |
2053 | { |
2014 | if (expect_false (ev_is_active (w))) |
2054 | if (expect_false (ev_is_active (w))) |
2015 | return; |
2055 | return; |
2016 | |
2056 | |
|
|
2057 | pri_adjust (EV_A_ (W)w); |
|
|
2058 | |
|
|
2059 | { |
|
|
2060 | int active = ++idlecnt [ABSPRI (w)]; |
|
|
2061 | |
|
|
2062 | ++idleall; |
2017 | ev_start (EV_A_ (W)w, ++idlecnt); |
2063 | ev_start (EV_A_ (W)w, active); |
|
|
2064 | |
2018 | array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
2065 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
2019 | idles [idlecnt - 1] = w; |
2066 | idles [ABSPRI (w)][active - 1] = w; |
|
|
2067 | } |
2020 | } |
2068 | } |
2021 | |
2069 | |
2022 | void |
2070 | void |
2023 | ev_idle_stop (EV_P_ ev_idle *w) |
2071 | ev_idle_stop (EV_P_ ev_idle *w) |
2024 | { |
2072 | { |
2025 | ev_clear_pending (EV_A_ (W)w); |
2073 | clear_pending (EV_A_ (W)w); |
2026 | if (expect_false (!ev_is_active (w))) |
2074 | if (expect_false (!ev_is_active (w))) |
2027 | return; |
2075 | return; |
2028 | |
2076 | |
2029 | { |
2077 | { |
2030 | int active = ((W)w)->active; |
2078 | int active = ((W)w)->active; |
2031 | idles [active - 1] = idles [--idlecnt]; |
2079 | |
|
|
2080 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
2032 | ((W)idles [active - 1])->active = active; |
2081 | ((W)idles [ABSPRI (w)][active - 1])->active = active; |
|
|
2082 | |
|
|
2083 | ev_stop (EV_A_ (W)w); |
|
|
2084 | --idleall; |
2033 | } |
2085 | } |
2034 | |
|
|
2035 | ev_stop (EV_A_ (W)w); |
|
|
2036 | } |
2086 | } |
|
|
2087 | #endif |
2037 | |
2088 | |
2038 | void |
2089 | void |
2039 | ev_prepare_start (EV_P_ ev_prepare *w) |
2090 | ev_prepare_start (EV_P_ ev_prepare *w) |
2040 | { |
2091 | { |
2041 | if (expect_false (ev_is_active (w))) |
2092 | if (expect_false (ev_is_active (w))) |
… | |
… | |
2047 | } |
2098 | } |
2048 | |
2099 | |
2049 | void |
2100 | void |
2050 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2101 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2051 | { |
2102 | { |
2052 | ev_clear_pending (EV_A_ (W)w); |
2103 | clear_pending (EV_A_ (W)w); |
2053 | if (expect_false (!ev_is_active (w))) |
2104 | if (expect_false (!ev_is_active (w))) |
2054 | return; |
2105 | return; |
2055 | |
2106 | |
2056 | { |
2107 | { |
2057 | int active = ((W)w)->active; |
2108 | int active = ((W)w)->active; |
… | |
… | |
2074 | } |
2125 | } |
2075 | |
2126 | |
2076 | void |
2127 | void |
2077 | ev_check_stop (EV_P_ ev_check *w) |
2128 | ev_check_stop (EV_P_ ev_check *w) |
2078 | { |
2129 | { |
2079 | ev_clear_pending (EV_A_ (W)w); |
2130 | clear_pending (EV_A_ (W)w); |
2080 | if (expect_false (!ev_is_active (w))) |
2131 | if (expect_false (!ev_is_active (w))) |
2081 | return; |
2132 | return; |
2082 | |
2133 | |
2083 | { |
2134 | { |
2084 | int active = ((W)w)->active; |
2135 | int active = ((W)w)->active; |
… | |
… | |
2126 | } |
2177 | } |
2127 | |
2178 | |
2128 | void |
2179 | void |
2129 | ev_embed_stop (EV_P_ ev_embed *w) |
2180 | ev_embed_stop (EV_P_ ev_embed *w) |
2130 | { |
2181 | { |
2131 | ev_clear_pending (EV_A_ (W)w); |
2182 | clear_pending (EV_A_ (W)w); |
2132 | if (expect_false (!ev_is_active (w))) |
2183 | if (expect_false (!ev_is_active (w))) |
2133 | return; |
2184 | return; |
2134 | |
2185 | |
2135 | ev_io_stop (EV_A_ &w->io); |
2186 | ev_io_stop (EV_A_ &w->io); |
2136 | |
2187 | |
… | |
… | |
2151 | } |
2202 | } |
2152 | |
2203 | |
2153 | void |
2204 | void |
2154 | ev_fork_stop (EV_P_ ev_fork *w) |
2205 | ev_fork_stop (EV_P_ ev_fork *w) |
2155 | { |
2206 | { |
2156 | ev_clear_pending (EV_A_ (W)w); |
2207 | clear_pending (EV_A_ (W)w); |
2157 | if (expect_false (!ev_is_active (w))) |
2208 | if (expect_false (!ev_is_active (w))) |
2158 | return; |
2209 | return; |
2159 | |
2210 | |
2160 | { |
2211 | { |
2161 | int active = ((W)w)->active; |
2212 | int active = ((W)w)->active; |