… | |
… | |
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 | void |
|
|
1538 | ev_clear_pending (EV_P_ void *w, int invoke) |
|
|
1539 | { |
|
|
1540 | W w_ = (W)w; |
|
|
1541 | int pending = w_->pending; |
|
|
1542 | |
|
|
1543 | if (pending) |
|
|
1544 | { |
|
|
1545 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
|
|
1546 | |
|
|
1547 | w_->pending = 0; |
|
|
1548 | p->w = 0; |
|
|
1549 | |
|
|
1550 | if (invoke) |
|
|
1551 | EV_CB_INVOKE (w_, p->events); |
|
|
1552 | } |
|
|
1553 | } |
|
|
1554 | |
|
|
1555 | void inline_size |
|
|
1556 | pri_adjust (EV_P_ W w) |
|
|
1557 | { |
|
|
1558 | int pri = w->priority; |
|
|
1559 | pri = pri < EV_MINPRI ? EV_MINPRI : pri; |
|
|
1560 | pri = pri > EV_MAXPRI ? EV_MAXPRI : pri; |
|
|
1561 | w->priority = pri; |
|
|
1562 | } |
|
|
1563 | |
1521 | void inline_speed |
1564 | void inline_speed |
1522 | ev_start (EV_P_ W w, int active) |
1565 | ev_start (EV_P_ W w, int active) |
1523 | { |
1566 | { |
1524 | if (w->priority < EV_MINPRI) w->priority = EV_MINPRI; |
1567 | pri_adjust (EV_A_ w); |
1525 | if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI; |
|
|
1526 | |
|
|
1527 | w->active = active; |
1568 | w->active = active; |
1528 | ev_ref (EV_A); |
1569 | ev_ref (EV_A); |
1529 | } |
1570 | } |
1530 | |
1571 | |
1531 | void inline_size |
1572 | void inline_size |
… | |
… | |
1555 | } |
1596 | } |
1556 | |
1597 | |
1557 | void |
1598 | void |
1558 | ev_io_stop (EV_P_ ev_io *w) |
1599 | ev_io_stop (EV_P_ ev_io *w) |
1559 | { |
1600 | { |
1560 | ev_clear_pending (EV_A_ (W)w); |
1601 | clear_pending (EV_A_ (W)w); |
1561 | if (expect_false (!ev_is_active (w))) |
1602 | if (expect_false (!ev_is_active (w))) |
1562 | return; |
1603 | return; |
1563 | |
1604 | |
1564 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1605 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1565 | |
1606 | |
… | |
… | |
1588 | } |
1629 | } |
1589 | |
1630 | |
1590 | void |
1631 | void |
1591 | ev_timer_stop (EV_P_ ev_timer *w) |
1632 | ev_timer_stop (EV_P_ ev_timer *w) |
1592 | { |
1633 | { |
1593 | ev_clear_pending (EV_A_ (W)w); |
1634 | clear_pending (EV_A_ (W)w); |
1594 | if (expect_false (!ev_is_active (w))) |
1635 | if (expect_false (!ev_is_active (w))) |
1595 | return; |
1636 | return; |
1596 | |
1637 | |
1597 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1638 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1598 | |
1639 | |
… | |
… | |
1656 | } |
1697 | } |
1657 | |
1698 | |
1658 | void |
1699 | void |
1659 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1700 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1660 | { |
1701 | { |
1661 | ev_clear_pending (EV_A_ (W)w); |
1702 | clear_pending (EV_A_ (W)w); |
1662 | if (expect_false (!ev_is_active (w))) |
1703 | if (expect_false (!ev_is_active (w))) |
1663 | return; |
1704 | return; |
1664 | |
1705 | |
1665 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1706 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1666 | |
1707 | |
… | |
… | |
1720 | } |
1761 | } |
1721 | |
1762 | |
1722 | void |
1763 | void |
1723 | ev_signal_stop (EV_P_ ev_signal *w) |
1764 | ev_signal_stop (EV_P_ ev_signal *w) |
1724 | { |
1765 | { |
1725 | ev_clear_pending (EV_A_ (W)w); |
1766 | clear_pending (EV_A_ (W)w); |
1726 | if (expect_false (!ev_is_active (w))) |
1767 | if (expect_false (!ev_is_active (w))) |
1727 | return; |
1768 | return; |
1728 | |
1769 | |
1729 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1770 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1730 | ev_stop (EV_A_ (W)w); |
1771 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1747 | } |
1788 | } |
1748 | |
1789 | |
1749 | void |
1790 | void |
1750 | ev_child_stop (EV_P_ ev_child *w) |
1791 | ev_child_stop (EV_P_ ev_child *w) |
1751 | { |
1792 | { |
1752 | ev_clear_pending (EV_A_ (W)w); |
1793 | clear_pending (EV_A_ (W)w); |
1753 | if (expect_false (!ev_is_active (w))) |
1794 | if (expect_false (!ev_is_active (w))) |
1754 | return; |
1795 | return; |
1755 | |
1796 | |
1756 | wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1797 | wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1757 | ev_stop (EV_A_ (W)w); |
1798 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1993 | } |
2034 | } |
1994 | |
2035 | |
1995 | void |
2036 | void |
1996 | ev_stat_stop (EV_P_ ev_stat *w) |
2037 | ev_stat_stop (EV_P_ ev_stat *w) |
1997 | { |
2038 | { |
1998 | ev_clear_pending (EV_A_ (W)w); |
2039 | clear_pending (EV_A_ (W)w); |
1999 | if (expect_false (!ev_is_active (w))) |
2040 | if (expect_false (!ev_is_active (w))) |
2000 | return; |
2041 | return; |
2001 | |
2042 | |
2002 | #if EV_USE_INOTIFY |
2043 | #if EV_USE_INOTIFY |
2003 | infy_del (EV_A_ w); |
2044 | infy_del (EV_A_ w); |
… | |
… | |
2006 | |
2047 | |
2007 | ev_stop (EV_A_ (W)w); |
2048 | ev_stop (EV_A_ (W)w); |
2008 | } |
2049 | } |
2009 | #endif |
2050 | #endif |
2010 | |
2051 | |
|
|
2052 | #if EV_IDLE_ENABLE |
2011 | void |
2053 | void |
2012 | ev_idle_start (EV_P_ ev_idle *w) |
2054 | ev_idle_start (EV_P_ ev_idle *w) |
2013 | { |
2055 | { |
2014 | if (expect_false (ev_is_active (w))) |
2056 | if (expect_false (ev_is_active (w))) |
2015 | return; |
2057 | return; |
2016 | |
2058 | |
|
|
2059 | pri_adjust (EV_A_ (W)w); |
|
|
2060 | |
|
|
2061 | { |
|
|
2062 | int active = ++idlecnt [ABSPRI (w)]; |
|
|
2063 | |
|
|
2064 | ++idleall; |
2017 | ev_start (EV_A_ (W)w, ++idlecnt); |
2065 | ev_start (EV_A_ (W)w, active); |
|
|
2066 | |
2018 | array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
2067 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
2019 | idles [idlecnt - 1] = w; |
2068 | idles [ABSPRI (w)][active - 1] = w; |
|
|
2069 | } |
2020 | } |
2070 | } |
2021 | |
2071 | |
2022 | void |
2072 | void |
2023 | ev_idle_stop (EV_P_ ev_idle *w) |
2073 | ev_idle_stop (EV_P_ ev_idle *w) |
2024 | { |
2074 | { |
2025 | ev_clear_pending (EV_A_ (W)w); |
2075 | clear_pending (EV_A_ (W)w); |
2026 | if (expect_false (!ev_is_active (w))) |
2076 | if (expect_false (!ev_is_active (w))) |
2027 | return; |
2077 | return; |
2028 | |
2078 | |
2029 | { |
2079 | { |
2030 | int active = ((W)w)->active; |
2080 | int active = ((W)w)->active; |
2031 | idles [active - 1] = idles [--idlecnt]; |
2081 | |
|
|
2082 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
2032 | ((W)idles [active - 1])->active = active; |
2083 | ((W)idles [ABSPRI (w)][active - 1])->active = active; |
|
|
2084 | |
|
|
2085 | ev_stop (EV_A_ (W)w); |
|
|
2086 | --idleall; |
2033 | } |
2087 | } |
2034 | |
|
|
2035 | ev_stop (EV_A_ (W)w); |
|
|
2036 | } |
2088 | } |
|
|
2089 | #endif |
2037 | |
2090 | |
2038 | void |
2091 | void |
2039 | ev_prepare_start (EV_P_ ev_prepare *w) |
2092 | ev_prepare_start (EV_P_ ev_prepare *w) |
2040 | { |
2093 | { |
2041 | if (expect_false (ev_is_active (w))) |
2094 | if (expect_false (ev_is_active (w))) |
… | |
… | |
2047 | } |
2100 | } |
2048 | |
2101 | |
2049 | void |
2102 | void |
2050 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2103 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2051 | { |
2104 | { |
2052 | ev_clear_pending (EV_A_ (W)w); |
2105 | clear_pending (EV_A_ (W)w); |
2053 | if (expect_false (!ev_is_active (w))) |
2106 | if (expect_false (!ev_is_active (w))) |
2054 | return; |
2107 | return; |
2055 | |
2108 | |
2056 | { |
2109 | { |
2057 | int active = ((W)w)->active; |
2110 | int active = ((W)w)->active; |
… | |
… | |
2074 | } |
2127 | } |
2075 | |
2128 | |
2076 | void |
2129 | void |
2077 | ev_check_stop (EV_P_ ev_check *w) |
2130 | ev_check_stop (EV_P_ ev_check *w) |
2078 | { |
2131 | { |
2079 | ev_clear_pending (EV_A_ (W)w); |
2132 | clear_pending (EV_A_ (W)w); |
2080 | if (expect_false (!ev_is_active (w))) |
2133 | if (expect_false (!ev_is_active (w))) |
2081 | return; |
2134 | return; |
2082 | |
2135 | |
2083 | { |
2136 | { |
2084 | int active = ((W)w)->active; |
2137 | int active = ((W)w)->active; |
… | |
… | |
2126 | } |
2179 | } |
2127 | |
2180 | |
2128 | void |
2181 | void |
2129 | ev_embed_stop (EV_P_ ev_embed *w) |
2182 | ev_embed_stop (EV_P_ ev_embed *w) |
2130 | { |
2183 | { |
2131 | ev_clear_pending (EV_A_ (W)w); |
2184 | clear_pending (EV_A_ (W)w); |
2132 | if (expect_false (!ev_is_active (w))) |
2185 | if (expect_false (!ev_is_active (w))) |
2133 | return; |
2186 | return; |
2134 | |
2187 | |
2135 | ev_io_stop (EV_A_ &w->io); |
2188 | ev_io_stop (EV_A_ &w->io); |
2136 | |
2189 | |
… | |
… | |
2151 | } |
2204 | } |
2152 | |
2205 | |
2153 | void |
2206 | void |
2154 | ev_fork_stop (EV_P_ ev_fork *w) |
2207 | ev_fork_stop (EV_P_ ev_fork *w) |
2155 | { |
2208 | { |
2156 | ev_clear_pending (EV_A_ (W)w); |
2209 | clear_pending (EV_A_ (W)w); |
2157 | if (expect_false (!ev_is_active (w))) |
2210 | if (expect_false (!ev_is_active (w))) |
2158 | return; |
2211 | return; |
2159 | |
2212 | |
2160 | { |
2213 | { |
2161 | int active = ((W)w)->active; |
2214 | int active = ((W)w)->active; |