… | |
… | |
222 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
222 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
223 | /*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */ |
223 | /*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */ |
224 | |
224 | |
225 | #if __GNUC__ >= 3 |
225 | #if __GNUC__ >= 3 |
226 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
226 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
227 | # define inline_size static inline /* inline for codesize */ |
|
|
228 | # if EV_MINIMAL |
|
|
229 | # define noinline __attribute__ ((noinline)) |
227 | # define noinline __attribute__ ((noinline)) |
230 | # define inline_speed static noinline |
|
|
231 | # else |
|
|
232 | # define noinline |
|
|
233 | # define inline_speed static inline |
|
|
234 | # endif |
|
|
235 | #else |
228 | #else |
236 | # define expect(expr,value) (expr) |
229 | # define expect(expr,value) (expr) |
237 | # define inline_speed static |
|
|
238 | # define inline_size static |
|
|
239 | # define noinline |
230 | # define noinline |
|
|
231 | # if __STDC_VERSION__ < 199901L |
|
|
232 | # define inline |
|
|
233 | # endif |
240 | #endif |
234 | #endif |
241 | |
235 | |
242 | #define expect_false(expr) expect ((expr) != 0, 0) |
236 | #define expect_false(expr) expect ((expr) != 0, 0) |
243 | #define expect_true(expr) expect ((expr) != 0, 1) |
237 | #define expect_true(expr) expect ((expr) != 0, 1) |
|
|
238 | #define inline_size static inline |
|
|
239 | |
|
|
240 | #if EV_MINIMAL |
|
|
241 | # define inline_speed static noinline |
|
|
242 | #else |
|
|
243 | # define inline_speed static inline |
|
|
244 | #endif |
244 | |
245 | |
245 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
246 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
246 | #define ABSPRI(w) ((w)->priority - EV_MINPRI) |
247 | #define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
247 | |
248 | |
248 | #define EMPTY0 /* required for microsofts broken pseudo-c compiler */ |
249 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
249 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
250 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
250 | |
251 | |
251 | typedef ev_watcher *W; |
252 | typedef ev_watcher *W; |
252 | typedef ev_watcher_list *WL; |
253 | typedef ev_watcher_list *WL; |
253 | typedef ev_watcher_time *WT; |
254 | typedef ev_watcher_time *WT; |
… | |
… | |
396 | { |
397 | { |
397 | return ev_rt_now; |
398 | return ev_rt_now; |
398 | } |
399 | } |
399 | #endif |
400 | #endif |
400 | |
401 | |
401 | #define array_roundsize(type,n) (((n) | 4) & ~3) |
402 | int inline_size |
|
|
403 | array_nextsize (int elem, int cur, int cnt) |
|
|
404 | { |
|
|
405 | int ncur = cur + 1; |
|
|
406 | |
|
|
407 | do |
|
|
408 | ncur <<= 1; |
|
|
409 | while (cnt > ncur); |
|
|
410 | |
|
|
411 | /* if size > 4096, round to 4096 - 4 * longs to accomodate malloc overhead */ |
|
|
412 | if (elem * ncur > 4096) |
|
|
413 | { |
|
|
414 | ncur *= elem; |
|
|
415 | ncur = (ncur + elem + 4095 + sizeof (void *) * 4) & ~4095; |
|
|
416 | ncur = ncur - sizeof (void *) * 4; |
|
|
417 | ncur /= elem; |
|
|
418 | } |
|
|
419 | |
|
|
420 | return ncur; |
|
|
421 | } |
|
|
422 | |
|
|
423 | inline_speed void * |
|
|
424 | array_realloc (int elem, void *base, int *cur, int cnt) |
|
|
425 | { |
|
|
426 | *cur = array_nextsize (elem, *cur, cnt); |
|
|
427 | return ev_realloc (base, elem * *cur); |
|
|
428 | } |
402 | |
429 | |
403 | #define array_needsize(type,base,cur,cnt,init) \ |
430 | #define array_needsize(type,base,cur,cnt,init) \ |
404 | if (expect_false ((cnt) > cur)) \ |
431 | if (expect_false ((cnt) > (cur))) \ |
405 | { \ |
432 | { \ |
406 | int newcnt = cur; \ |
433 | int ocur_ = (cur); \ |
407 | do \ |
434 | (base) = (type *)array_realloc \ |
408 | { \ |
435 | (sizeof (type), (base), &(cur), (cnt)); \ |
409 | newcnt = array_roundsize (type, newcnt << 1); \ |
436 | init ((base) + (ocur_), (cur) - ocur_); \ |
410 | } \ |
|
|
411 | while ((cnt) > newcnt); \ |
|
|
412 | \ |
|
|
413 | base = (type *)ev_realloc (base, sizeof (type) * (newcnt));\ |
|
|
414 | init (base + cur, newcnt - cur); \ |
|
|
415 | cur = newcnt; \ |
|
|
416 | } |
437 | } |
417 | |
438 | |
|
|
439 | #if 0 |
418 | #define array_slim(type,stem) \ |
440 | #define array_slim(type,stem) \ |
419 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
441 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
420 | { \ |
442 | { \ |
421 | stem ## max = array_roundsize (stem ## cnt >> 1); \ |
443 | stem ## max = array_roundsize (stem ## cnt >> 1); \ |
422 | base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\ |
444 | base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\ |
423 | fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ |
445 | fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ |
424 | } |
446 | } |
|
|
447 | #endif |
425 | |
448 | |
426 | #define array_free(stem, idx) \ |
449 | #define array_free(stem, idx) \ |
427 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
450 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
428 | |
451 | |
429 | /*****************************************************************************/ |
452 | /*****************************************************************************/ |
… | |
… | |
485 | } |
508 | } |
486 | |
509 | |
487 | void |
510 | void |
488 | ev_feed_fd_event (EV_P_ int fd, int revents) |
511 | ev_feed_fd_event (EV_P_ int fd, int revents) |
489 | { |
512 | { |
|
|
513 | if (fd >= 0 && fd < anfdmax) |
490 | fd_event (EV_A_ fd, revents); |
514 | fd_event (EV_A_ fd, revents); |
491 | } |
515 | } |
492 | |
516 | |
493 | void inline_size |
517 | void inline_size |
494 | fd_reify (EV_P) |
518 | fd_reify (EV_P) |
495 | { |
519 | { |
… | |
… | |
764 | ev_child *w; |
788 | ev_child *w; |
765 | |
789 | |
766 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
790 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
767 | if (w->pid == pid || !w->pid) |
791 | if (w->pid == pid || !w->pid) |
768 | { |
792 | { |
769 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
793 | ev_set_priority (w, ev_priority (sw)); /* need to do it *now* */ |
770 | w->rpid = pid; |
794 | w->rpid = pid; |
771 | w->rstatus = status; |
795 | w->rstatus = status; |
772 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
796 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
773 | } |
797 | } |
774 | } |
798 | } |
775 | |
799 | |
776 | #ifndef WCONTINUED |
800 | #ifndef WCONTINUED |
… | |
… | |
886 | ev_backend (EV_P) |
910 | ev_backend (EV_P) |
887 | { |
911 | { |
888 | return backend; |
912 | return backend; |
889 | } |
913 | } |
890 | |
914 | |
|
|
915 | unsigned int |
|
|
916 | ev_loop_count (EV_P) |
|
|
917 | { |
|
|
918 | return loop_count; |
|
|
919 | } |
|
|
920 | |
891 | static void noinline |
921 | static void noinline |
892 | loop_init (EV_P_ unsigned int flags) |
922 | loop_init (EV_P_ unsigned int flags) |
893 | { |
923 | { |
894 | if (!backend) |
924 | if (!backend) |
895 | { |
925 | { |
… | |
… | |
975 | #if EV_USE_SELECT |
1005 | #if EV_USE_SELECT |
976 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
1006 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
977 | #endif |
1007 | #endif |
978 | |
1008 | |
979 | for (i = NUMPRI; i--; ) |
1009 | for (i = NUMPRI; i--; ) |
|
|
1010 | { |
980 | array_free (pending, [i]); |
1011 | array_free (pending, [i]); |
|
|
1012 | #if EV_IDLE_ENABLE |
|
|
1013 | array_free (idle, [i]); |
|
|
1014 | #endif |
|
|
1015 | } |
981 | |
1016 | |
982 | /* have to use the microsoft-never-gets-it-right macro */ |
1017 | /* have to use the microsoft-never-gets-it-right macro */ |
983 | array_free (fdchange, EMPTY0); |
1018 | array_free (fdchange, EMPTY); |
984 | array_free (timer, EMPTY0); |
1019 | array_free (timer, EMPTY); |
985 | #if EV_PERIODIC_ENABLE |
1020 | #if EV_PERIODIC_ENABLE |
986 | array_free (periodic, EMPTY0); |
1021 | array_free (periodic, EMPTY); |
987 | #endif |
1022 | #endif |
988 | array_free (idle, EMPTY0); |
|
|
989 | array_free (prepare, EMPTY0); |
1023 | array_free (prepare, EMPTY); |
990 | array_free (check, EMPTY0); |
1024 | array_free (check, EMPTY); |
991 | |
1025 | |
992 | backend = 0; |
1026 | backend = 0; |
993 | } |
1027 | } |
994 | |
1028 | |
995 | void inline_size infy_fork (EV_P); |
1029 | void inline_size infy_fork (EV_P); |
… | |
… | |
1131 | postfork = 1; |
1165 | postfork = 1; |
1132 | } |
1166 | } |
1133 | |
1167 | |
1134 | /*****************************************************************************/ |
1168 | /*****************************************************************************/ |
1135 | |
1169 | |
1136 | int inline_size |
1170 | void |
1137 | any_pending (EV_P) |
1171 | ev_invoke (EV_P_ void *w, int revents) |
1138 | { |
1172 | { |
1139 | int pri; |
1173 | EV_CB_INVOKE ((W)w, revents); |
1140 | |
|
|
1141 | for (pri = NUMPRI; pri--; ) |
|
|
1142 | if (pendingcnt [pri]) |
|
|
1143 | return 1; |
|
|
1144 | |
|
|
1145 | return 0; |
|
|
1146 | } |
1174 | } |
1147 | |
1175 | |
1148 | void inline_speed |
1176 | void inline_speed |
1149 | call_pending (EV_P) |
1177 | call_pending (EV_P) |
1150 | { |
1178 | { |
… | |
… | |
1242 | for (i = periodiccnt >> 1; i--; ) |
1270 | for (i = periodiccnt >> 1; i--; ) |
1243 | downheap ((WT *)periodics, periodiccnt, i); |
1271 | downheap ((WT *)periodics, periodiccnt, i); |
1244 | } |
1272 | } |
1245 | #endif |
1273 | #endif |
1246 | |
1274 | |
|
|
1275 | #if EV_IDLE_ENABLE |
|
|
1276 | void inline_size |
|
|
1277 | idle_reify (EV_P) |
|
|
1278 | { |
|
|
1279 | if (expect_false (idleall)) |
|
|
1280 | { |
|
|
1281 | int pri; |
|
|
1282 | |
|
|
1283 | for (pri = NUMPRI; pri--; ) |
|
|
1284 | { |
|
|
1285 | if (pendingcnt [pri]) |
|
|
1286 | break; |
|
|
1287 | |
|
|
1288 | if (idlecnt [pri]) |
|
|
1289 | { |
|
|
1290 | queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE); |
|
|
1291 | break; |
|
|
1292 | } |
|
|
1293 | } |
|
|
1294 | } |
|
|
1295 | } |
|
|
1296 | #endif |
|
|
1297 | |
1247 | int inline_size |
1298 | int inline_size |
1248 | time_update_monotonic (EV_P) |
1299 | time_update_monotonic (EV_P) |
1249 | { |
1300 | { |
1250 | mn_now = get_clock (); |
1301 | mn_now = get_clock (); |
1251 | |
1302 | |
… | |
… | |
1342 | ? EVUNLOOP_ONE |
1393 | ? EVUNLOOP_ONE |
1343 | : EVUNLOOP_CANCEL; |
1394 | : EVUNLOOP_CANCEL; |
1344 | |
1395 | |
1345 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
1396 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
1346 | |
1397 | |
1347 | while (expect_false (!activecnt)) |
1398 | do |
1348 | { |
1399 | { |
1349 | #ifndef _WIN32 |
1400 | #ifndef _WIN32 |
1350 | if (expect_false (curpid)) /* penalise the forking check even more */ |
1401 | if (expect_false (curpid)) /* penalise the forking check even more */ |
1351 | if (expect_false (getpid () != curpid)) |
1402 | if (expect_false (getpid () != curpid)) |
1352 | { |
1403 | { |
… | |
… | |
1384 | |
1435 | |
1385 | /* calculate blocking time */ |
1436 | /* calculate blocking time */ |
1386 | { |
1437 | { |
1387 | ev_tstamp block; |
1438 | ev_tstamp block; |
1388 | |
1439 | |
1389 | if (expect_false (flags & EVLOOP_NONBLOCK || idlecnt || !activecnt)) |
1440 | if (expect_false (flags & EVLOOP_NONBLOCK || idleall || !activecnt)) |
1390 | block = 0.; /* do not block at all */ |
1441 | block = 0.; /* do not block at all */ |
1391 | else |
1442 | else |
1392 | { |
1443 | { |
1393 | /* update time to cancel out callback processing overhead */ |
1444 | /* update time to cancel out callback processing overhead */ |
1394 | #if EV_USE_MONOTONIC |
1445 | #if EV_USE_MONOTONIC |
… | |
… | |
1418 | #endif |
1469 | #endif |
1419 | |
1470 | |
1420 | if (expect_false (block < 0.)) block = 0.; |
1471 | if (expect_false (block < 0.)) block = 0.; |
1421 | } |
1472 | } |
1422 | |
1473 | |
|
|
1474 | ++loop_count; |
1423 | backend_poll (EV_A_ block); |
1475 | backend_poll (EV_A_ block); |
1424 | } |
1476 | } |
1425 | |
1477 | |
1426 | /* update ev_rt_now, do magic */ |
1478 | /* update ev_rt_now, do magic */ |
1427 | time_update (EV_A); |
1479 | time_update (EV_A); |
… | |
… | |
1430 | timers_reify (EV_A); /* relative timers called last */ |
1482 | timers_reify (EV_A); /* relative timers called last */ |
1431 | #if EV_PERIODIC_ENABLE |
1483 | #if EV_PERIODIC_ENABLE |
1432 | periodics_reify (EV_A); /* absolute timers called first */ |
1484 | periodics_reify (EV_A); /* absolute timers called first */ |
1433 | #endif |
1485 | #endif |
1434 | |
1486 | |
|
|
1487 | #if EV_IDLE_ENABLE |
1435 | /* queue idle watchers unless other events are pending */ |
1488 | /* queue idle watchers unless other events are pending */ |
1436 | if (idlecnt && !any_pending (EV_A)) |
1489 | idle_reify (EV_A); |
1437 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1490 | #endif |
1438 | |
1491 | |
1439 | /* queue check watchers, to be executed first */ |
1492 | /* queue check watchers, to be executed first */ |
1440 | if (expect_false (checkcnt)) |
1493 | if (expect_false (checkcnt)) |
1441 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1494 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1442 | |
1495 | |
1443 | call_pending (EV_A); |
1496 | call_pending (EV_A); |
1444 | |
1497 | |
1445 | if (expect_false (loop_done)) |
|
|
1446 | break; |
|
|
1447 | } |
1498 | } |
|
|
1499 | while (expect_true (activecnt && !loop_done)); |
1448 | |
1500 | |
1449 | if (loop_done == EVUNLOOP_ONE) |
1501 | if (loop_done == EVUNLOOP_ONE) |
1450 | loop_done = EVUNLOOP_CANCEL; |
1502 | loop_done = EVUNLOOP_CANCEL; |
1451 | } |
1503 | } |
1452 | |
1504 | |
… | |
… | |
1479 | head = &(*head)->next; |
1531 | head = &(*head)->next; |
1480 | } |
1532 | } |
1481 | } |
1533 | } |
1482 | |
1534 | |
1483 | void inline_speed |
1535 | void inline_speed |
1484 | ev_clear_pending (EV_P_ W w) |
1536 | clear_pending (EV_P_ W w) |
1485 | { |
1537 | { |
1486 | if (w->pending) |
1538 | if (w->pending) |
1487 | { |
1539 | { |
1488 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
1540 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
1489 | w->pending = 0; |
1541 | w->pending = 0; |
1490 | } |
1542 | } |
1491 | } |
1543 | } |
1492 | |
1544 | |
|
|
1545 | int |
|
|
1546 | ev_clear_pending (EV_P_ void *w) |
|
|
1547 | { |
|
|
1548 | W w_ = (W)w; |
|
|
1549 | int pending = w_->pending; |
|
|
1550 | |
|
|
1551 | if (!pending) |
|
|
1552 | 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 | |
|
|
1561 | void inline_size |
|
|
1562 | pri_adjust (EV_P_ W w) |
|
|
1563 | { |
|
|
1564 | int pri = w->priority; |
|
|
1565 | pri = pri < EV_MINPRI ? EV_MINPRI : pri; |
|
|
1566 | pri = pri > EV_MAXPRI ? EV_MAXPRI : pri; |
|
|
1567 | w->priority = pri; |
|
|
1568 | } |
|
|
1569 | |
1493 | void inline_speed |
1570 | void inline_speed |
1494 | ev_start (EV_P_ W w, int active) |
1571 | ev_start (EV_P_ W w, int active) |
1495 | { |
1572 | { |
1496 | if (w->priority < EV_MINPRI) w->priority = EV_MINPRI; |
1573 | pri_adjust (EV_A_ w); |
1497 | if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI; |
|
|
1498 | |
|
|
1499 | w->active = active; |
1574 | w->active = active; |
1500 | ev_ref (EV_A); |
1575 | ev_ref (EV_A); |
1501 | } |
1576 | } |
1502 | |
1577 | |
1503 | void inline_size |
1578 | void inline_size |
… | |
… | |
1527 | } |
1602 | } |
1528 | |
1603 | |
1529 | void |
1604 | void |
1530 | ev_io_stop (EV_P_ ev_io *w) |
1605 | ev_io_stop (EV_P_ ev_io *w) |
1531 | { |
1606 | { |
1532 | ev_clear_pending (EV_A_ (W)w); |
1607 | clear_pending (EV_A_ (W)w); |
1533 | if (expect_false (!ev_is_active (w))) |
1608 | if (expect_false (!ev_is_active (w))) |
1534 | return; |
1609 | return; |
1535 | |
1610 | |
1536 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1611 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1537 | |
1612 | |
… | |
… | |
1560 | } |
1635 | } |
1561 | |
1636 | |
1562 | void |
1637 | void |
1563 | ev_timer_stop (EV_P_ ev_timer *w) |
1638 | ev_timer_stop (EV_P_ ev_timer *w) |
1564 | { |
1639 | { |
1565 | ev_clear_pending (EV_A_ (W)w); |
1640 | clear_pending (EV_A_ (W)w); |
1566 | if (expect_false (!ev_is_active (w))) |
1641 | if (expect_false (!ev_is_active (w))) |
1567 | return; |
1642 | return; |
1568 | |
1643 | |
1569 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1644 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1570 | |
1645 | |
… | |
… | |
1628 | } |
1703 | } |
1629 | |
1704 | |
1630 | void |
1705 | void |
1631 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1706 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1632 | { |
1707 | { |
1633 | ev_clear_pending (EV_A_ (W)w); |
1708 | clear_pending (EV_A_ (W)w); |
1634 | if (expect_false (!ev_is_active (w))) |
1709 | if (expect_false (!ev_is_active (w))) |
1635 | return; |
1710 | return; |
1636 | |
1711 | |
1637 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1712 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1638 | |
1713 | |
… | |
… | |
1692 | } |
1767 | } |
1693 | |
1768 | |
1694 | void |
1769 | void |
1695 | ev_signal_stop (EV_P_ ev_signal *w) |
1770 | ev_signal_stop (EV_P_ ev_signal *w) |
1696 | { |
1771 | { |
1697 | ev_clear_pending (EV_A_ (W)w); |
1772 | clear_pending (EV_A_ (W)w); |
1698 | if (expect_false (!ev_is_active (w))) |
1773 | if (expect_false (!ev_is_active (w))) |
1699 | return; |
1774 | return; |
1700 | |
1775 | |
1701 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1776 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1702 | ev_stop (EV_A_ (W)w); |
1777 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1719 | } |
1794 | } |
1720 | |
1795 | |
1721 | void |
1796 | void |
1722 | ev_child_stop (EV_P_ ev_child *w) |
1797 | ev_child_stop (EV_P_ ev_child *w) |
1723 | { |
1798 | { |
1724 | ev_clear_pending (EV_A_ (W)w); |
1799 | clear_pending (EV_A_ (W)w); |
1725 | if (expect_false (!ev_is_active (w))) |
1800 | if (expect_false (!ev_is_active (w))) |
1726 | return; |
1801 | return; |
1727 | |
1802 | |
1728 | wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1803 | wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1729 | ev_stop (EV_A_ (W)w); |
1804 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1965 | } |
2040 | } |
1966 | |
2041 | |
1967 | void |
2042 | void |
1968 | ev_stat_stop (EV_P_ ev_stat *w) |
2043 | ev_stat_stop (EV_P_ ev_stat *w) |
1969 | { |
2044 | { |
1970 | ev_clear_pending (EV_A_ (W)w); |
2045 | clear_pending (EV_A_ (W)w); |
1971 | if (expect_false (!ev_is_active (w))) |
2046 | if (expect_false (!ev_is_active (w))) |
1972 | return; |
2047 | return; |
1973 | |
2048 | |
1974 | #if EV_USE_INOTIFY |
2049 | #if EV_USE_INOTIFY |
1975 | infy_del (EV_A_ w); |
2050 | infy_del (EV_A_ w); |
… | |
… | |
1978 | |
2053 | |
1979 | ev_stop (EV_A_ (W)w); |
2054 | ev_stop (EV_A_ (W)w); |
1980 | } |
2055 | } |
1981 | #endif |
2056 | #endif |
1982 | |
2057 | |
|
|
2058 | #if EV_IDLE_ENABLE |
1983 | void |
2059 | void |
1984 | ev_idle_start (EV_P_ ev_idle *w) |
2060 | ev_idle_start (EV_P_ ev_idle *w) |
1985 | { |
2061 | { |
1986 | if (expect_false (ev_is_active (w))) |
2062 | if (expect_false (ev_is_active (w))) |
1987 | return; |
2063 | return; |
1988 | |
2064 | |
|
|
2065 | pri_adjust (EV_A_ (W)w); |
|
|
2066 | |
|
|
2067 | { |
|
|
2068 | int active = ++idlecnt [ABSPRI (w)]; |
|
|
2069 | |
|
|
2070 | ++idleall; |
1989 | ev_start (EV_A_ (W)w, ++idlecnt); |
2071 | ev_start (EV_A_ (W)w, active); |
|
|
2072 | |
1990 | array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
2073 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
1991 | idles [idlecnt - 1] = w; |
2074 | idles [ABSPRI (w)][active - 1] = w; |
|
|
2075 | } |
1992 | } |
2076 | } |
1993 | |
2077 | |
1994 | void |
2078 | void |
1995 | ev_idle_stop (EV_P_ ev_idle *w) |
2079 | ev_idle_stop (EV_P_ ev_idle *w) |
1996 | { |
2080 | { |
1997 | ev_clear_pending (EV_A_ (W)w); |
2081 | clear_pending (EV_A_ (W)w); |
1998 | if (expect_false (!ev_is_active (w))) |
2082 | if (expect_false (!ev_is_active (w))) |
1999 | return; |
2083 | return; |
2000 | |
2084 | |
2001 | { |
2085 | { |
2002 | int active = ((W)w)->active; |
2086 | int active = ((W)w)->active; |
2003 | idles [active - 1] = idles [--idlecnt]; |
2087 | |
|
|
2088 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
2004 | ((W)idles [active - 1])->active = active; |
2089 | ((W)idles [ABSPRI (w)][active - 1])->active = active; |
|
|
2090 | |
|
|
2091 | ev_stop (EV_A_ (W)w); |
|
|
2092 | --idleall; |
2005 | } |
2093 | } |
2006 | |
|
|
2007 | ev_stop (EV_A_ (W)w); |
|
|
2008 | } |
2094 | } |
|
|
2095 | #endif |
2009 | |
2096 | |
2010 | void |
2097 | void |
2011 | ev_prepare_start (EV_P_ ev_prepare *w) |
2098 | ev_prepare_start (EV_P_ ev_prepare *w) |
2012 | { |
2099 | { |
2013 | if (expect_false (ev_is_active (w))) |
2100 | if (expect_false (ev_is_active (w))) |
… | |
… | |
2019 | } |
2106 | } |
2020 | |
2107 | |
2021 | void |
2108 | void |
2022 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2109 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2023 | { |
2110 | { |
2024 | ev_clear_pending (EV_A_ (W)w); |
2111 | clear_pending (EV_A_ (W)w); |
2025 | if (expect_false (!ev_is_active (w))) |
2112 | if (expect_false (!ev_is_active (w))) |
2026 | return; |
2113 | return; |
2027 | |
2114 | |
2028 | { |
2115 | { |
2029 | int active = ((W)w)->active; |
2116 | int active = ((W)w)->active; |
… | |
… | |
2046 | } |
2133 | } |
2047 | |
2134 | |
2048 | void |
2135 | void |
2049 | ev_check_stop (EV_P_ ev_check *w) |
2136 | ev_check_stop (EV_P_ ev_check *w) |
2050 | { |
2137 | { |
2051 | ev_clear_pending (EV_A_ (W)w); |
2138 | clear_pending (EV_A_ (W)w); |
2052 | if (expect_false (!ev_is_active (w))) |
2139 | if (expect_false (!ev_is_active (w))) |
2053 | return; |
2140 | return; |
2054 | |
2141 | |
2055 | { |
2142 | { |
2056 | int active = ((W)w)->active; |
2143 | int active = ((W)w)->active; |
… | |
… | |
2098 | } |
2185 | } |
2099 | |
2186 | |
2100 | void |
2187 | void |
2101 | ev_embed_stop (EV_P_ ev_embed *w) |
2188 | ev_embed_stop (EV_P_ ev_embed *w) |
2102 | { |
2189 | { |
2103 | ev_clear_pending (EV_A_ (W)w); |
2190 | clear_pending (EV_A_ (W)w); |
2104 | if (expect_false (!ev_is_active (w))) |
2191 | if (expect_false (!ev_is_active (w))) |
2105 | return; |
2192 | return; |
2106 | |
2193 | |
2107 | ev_io_stop (EV_A_ &w->io); |
2194 | ev_io_stop (EV_A_ &w->io); |
2108 | |
2195 | |
… | |
… | |
2123 | } |
2210 | } |
2124 | |
2211 | |
2125 | void |
2212 | void |
2126 | ev_fork_stop (EV_P_ ev_fork *w) |
2213 | ev_fork_stop (EV_P_ ev_fork *w) |
2127 | { |
2214 | { |
2128 | ev_clear_pending (EV_A_ (W)w); |
2215 | clear_pending (EV_A_ (W)w); |
2129 | if (expect_false (!ev_is_active (w))) |
2216 | if (expect_false (!ev_is_active (w))) |
2130 | return; |
2217 | return; |
2131 | |
2218 | |
2132 | { |
2219 | { |
2133 | int active = ((W)w)->active; |
2220 | int active = ((W)w)->active; |