… | |
… | |
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 | |
… | |
… | |
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 inline_size |
|
|
1538 | pri_adjust (EV_P_ W w) |
|
|
1539 | { |
|
|
1540 | int pri = w->priority; |
|
|
1541 | pri = pri < EV_MINPRI ? EV_MINPRI : pri; |
|
|
1542 | pri = pri > EV_MAXPRI ? EV_MAXPRI : pri; |
|
|
1543 | w->priority = pri; |
|
|
1544 | } |
|
|
1545 | |
1521 | void inline_speed |
1546 | void inline_speed |
1522 | ev_start (EV_P_ W w, int active) |
1547 | ev_start (EV_P_ W w, int active) |
1523 | { |
1548 | { |
1524 | if (w->priority < EV_MINPRI) w->priority = EV_MINPRI; |
1549 | pri_adjust (EV_A_ w); |
1525 | if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI; |
|
|
1526 | |
|
|
1527 | w->active = active; |
1550 | w->active = active; |
1528 | ev_ref (EV_A); |
1551 | ev_ref (EV_A); |
1529 | } |
1552 | } |
1530 | |
1553 | |
1531 | void inline_size |
1554 | void inline_size |
… | |
… | |
2006 | |
2029 | |
2007 | ev_stop (EV_A_ (W)w); |
2030 | ev_stop (EV_A_ (W)w); |
2008 | } |
2031 | } |
2009 | #endif |
2032 | #endif |
2010 | |
2033 | |
|
|
2034 | #if EV_IDLE_ENABLE |
2011 | void |
2035 | void |
2012 | ev_idle_start (EV_P_ ev_idle *w) |
2036 | ev_idle_start (EV_P_ ev_idle *w) |
2013 | { |
2037 | { |
2014 | if (expect_false (ev_is_active (w))) |
2038 | if (expect_false (ev_is_active (w))) |
2015 | return; |
2039 | return; |
2016 | |
2040 | |
|
|
2041 | pri_adjust (EV_A_ (W)w); |
|
|
2042 | |
|
|
2043 | { |
|
|
2044 | int active = ++idlecnt [ABSPRI (w)]; |
|
|
2045 | |
|
|
2046 | ++idleall; |
2017 | ev_start (EV_A_ (W)w, ++idlecnt); |
2047 | ev_start (EV_A_ (W)w, active); |
|
|
2048 | |
2018 | array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
2049 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
2019 | idles [idlecnt - 1] = w; |
2050 | idles [ABSPRI (w)][active - 1] = w; |
|
|
2051 | } |
2020 | } |
2052 | } |
2021 | |
2053 | |
2022 | void |
2054 | void |
2023 | ev_idle_stop (EV_P_ ev_idle *w) |
2055 | ev_idle_stop (EV_P_ ev_idle *w) |
2024 | { |
2056 | { |
… | |
… | |
2026 | if (expect_false (!ev_is_active (w))) |
2058 | if (expect_false (!ev_is_active (w))) |
2027 | return; |
2059 | return; |
2028 | |
2060 | |
2029 | { |
2061 | { |
2030 | int active = ((W)w)->active; |
2062 | int active = ((W)w)->active; |
2031 | idles [active - 1] = idles [--idlecnt]; |
2063 | |
|
|
2064 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
2032 | ((W)idles [active - 1])->active = active; |
2065 | ((W)idles [ABSPRI (w)][active - 1])->active = active; |
|
|
2066 | |
|
|
2067 | ev_stop (EV_A_ (W)w); |
|
|
2068 | --idleall; |
2033 | } |
2069 | } |
2034 | |
|
|
2035 | ev_stop (EV_A_ (W)w); |
|
|
2036 | } |
2070 | } |
|
|
2071 | #endif |
2037 | |
2072 | |
2038 | void |
2073 | void |
2039 | ev_prepare_start (EV_P_ ev_prepare *w) |
2074 | ev_prepare_start (EV_P_ ev_prepare *w) |
2040 | { |
2075 | { |
2041 | if (expect_false (ev_is_active (w))) |
2076 | if (expect_false (ev_is_active (w))) |