… | |
… | |
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; |
… | |
… | |
396 | { |
396 | { |
397 | return ev_rt_now; |
397 | return ev_rt_now; |
398 | } |
398 | } |
399 | #endif |
399 | #endif |
400 | |
400 | |
401 | #define array_roundsize(type,n) (((n) | 4) & ~3) |
401 | int inline_size |
|
|
402 | array_nextsize (int elem, int cur, int cnt) |
|
|
403 | { |
|
|
404 | int ncur = cur + 1; |
|
|
405 | |
|
|
406 | do |
|
|
407 | ncur <<= 1; |
|
|
408 | while (cnt > ncur); |
|
|
409 | |
|
|
410 | /* if size > 4096, round to 4096 - 4 * longs to accomodate malloc overhead */ |
|
|
411 | if (elem * ncur > 4096) |
|
|
412 | { |
|
|
413 | ncur *= elem; |
|
|
414 | ncur = (ncur + elem + 4095 + sizeof (void *) * 4) & ~4095; |
|
|
415 | ncur = ncur - sizeof (void *) * 4; |
|
|
416 | ncur /= elem; |
|
|
417 | } |
|
|
418 | |
|
|
419 | return ncur; |
|
|
420 | } |
|
|
421 | |
|
|
422 | inline_speed void * |
|
|
423 | array_realloc (int elem, void *base, int *cur, int cnt) |
|
|
424 | { |
|
|
425 | *cur = array_nextsize (elem, *cur, cnt); |
|
|
426 | return ev_realloc (base, elem * *cur); |
|
|
427 | } |
402 | |
428 | |
403 | #define array_needsize(type,base,cur,cnt,init) \ |
429 | #define array_needsize(type,base,cur,cnt,init) \ |
404 | if (expect_false ((cnt) > cur)) \ |
430 | if (expect_false ((cnt) > (cur))) \ |
405 | { \ |
431 | { \ |
406 | int newcnt = cur; \ |
432 | int ocur_ = (cur); \ |
407 | do \ |
433 | (base) = (type *)array_realloc \ |
408 | { \ |
434 | (sizeof (type), (base), &(cur), (cnt)); \ |
409 | newcnt = array_roundsize (type, newcnt << 1); \ |
435 | 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 | } |
436 | } |
417 | |
437 | |
|
|
438 | #if 0 |
418 | #define array_slim(type,stem) \ |
439 | #define array_slim(type,stem) \ |
419 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
440 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
420 | { \ |
441 | { \ |
421 | stem ## max = array_roundsize (stem ## cnt >> 1); \ |
442 | stem ## max = array_roundsize (stem ## cnt >> 1); \ |
422 | base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\ |
443 | base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\ |
423 | fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ |
444 | fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ |
424 | } |
445 | } |
|
|
446 | #endif |
425 | |
447 | |
426 | #define array_free(stem, idx) \ |
448 | #define array_free(stem, idx) \ |
427 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
449 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
428 | |
450 | |
429 | /*****************************************************************************/ |
451 | /*****************************************************************************/ |
… | |
… | |
764 | ev_child *w; |
786 | ev_child *w; |
765 | |
787 | |
766 | 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) |
767 | if (w->pid == pid || !w->pid) |
789 | if (w->pid == pid || !w->pid) |
768 | { |
790 | { |
769 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
791 | ev_set_priority (w, ev_priority (sw)); /* need to do it *now* */ |
770 | w->rpid = pid; |
792 | w->rpid = pid; |
771 | w->rstatus = status; |
793 | w->rstatus = status; |
772 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
794 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
773 | } |
795 | } |
774 | } |
796 | } |
775 | |
797 | |
776 | #ifndef WCONTINUED |
798 | #ifndef WCONTINUED |
… | |
… | |
886 | ev_backend (EV_P) |
908 | ev_backend (EV_P) |
887 | { |
909 | { |
888 | return backend; |
910 | return backend; |
889 | } |
911 | } |
890 | |
912 | |
|
|
913 | unsigned int |
|
|
914 | ev_loop_count (EV_P) |
|
|
915 | { |
|
|
916 | return loop_count; |
|
|
917 | } |
|
|
918 | |
891 | static void noinline |
919 | static void noinline |
892 | loop_init (EV_P_ unsigned int flags) |
920 | loop_init (EV_P_ unsigned int flags) |
893 | { |
921 | { |
894 | if (!backend) |
922 | if (!backend) |
895 | { |
923 | { |
… | |
… | |
904 | ev_rt_now = ev_time (); |
932 | ev_rt_now = ev_time (); |
905 | mn_now = get_clock (); |
933 | mn_now = get_clock (); |
906 | now_floor = mn_now; |
934 | now_floor = mn_now; |
907 | rtmn_diff = ev_rt_now - mn_now; |
935 | rtmn_diff = ev_rt_now - mn_now; |
908 | |
936 | |
|
|
937 | /* pid check not overridable via env */ |
|
|
938 | #ifndef _WIN32 |
|
|
939 | if (flags & EVFLAG_FORKCHECK) |
|
|
940 | curpid = getpid (); |
|
|
941 | #endif |
|
|
942 | |
909 | if (!(flags & EVFLAG_NOENV) |
943 | if (!(flags & EVFLAG_NOENV) |
910 | && !enable_secure () |
944 | && !enable_secure () |
911 | && getenv ("LIBEV_FLAGS")) |
945 | && getenv ("LIBEV_FLAGS")) |
912 | flags = atoi (getenv ("LIBEV_FLAGS")); |
946 | flags = atoi (getenv ("LIBEV_FLAGS")); |
913 | |
947 | |
… | |
… | |
969 | #if EV_USE_SELECT |
1003 | #if EV_USE_SELECT |
970 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
1004 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
971 | #endif |
1005 | #endif |
972 | |
1006 | |
973 | for (i = NUMPRI; i--; ) |
1007 | for (i = NUMPRI; i--; ) |
|
|
1008 | { |
974 | array_free (pending, [i]); |
1009 | array_free (pending, [i]); |
|
|
1010 | #if EV_IDLE_ENABLE |
|
|
1011 | array_free (idle, [i]); |
|
|
1012 | #endif |
|
|
1013 | } |
975 | |
1014 | |
976 | /* have to use the microsoft-never-gets-it-right macro */ |
1015 | /* have to use the microsoft-never-gets-it-right macro */ |
977 | array_free (fdchange, EMPTY0); |
1016 | array_free (fdchange, EMPTY); |
978 | array_free (timer, EMPTY0); |
1017 | array_free (timer, EMPTY); |
979 | #if EV_PERIODIC_ENABLE |
1018 | #if EV_PERIODIC_ENABLE |
980 | array_free (periodic, EMPTY0); |
1019 | array_free (periodic, EMPTY); |
981 | #endif |
1020 | #endif |
982 | array_free (idle, EMPTY0); |
|
|
983 | array_free (prepare, EMPTY0); |
1021 | array_free (prepare, EMPTY); |
984 | array_free (check, EMPTY0); |
1022 | array_free (check, EMPTY); |
985 | |
1023 | |
986 | backend = 0; |
1024 | backend = 0; |
987 | } |
1025 | } |
988 | |
1026 | |
989 | void inline_size infy_fork (EV_P); |
1027 | void inline_size infy_fork (EV_P); |
… | |
… | |
1124 | if (backend) |
1162 | if (backend) |
1125 | postfork = 1; |
1163 | postfork = 1; |
1126 | } |
1164 | } |
1127 | |
1165 | |
1128 | /*****************************************************************************/ |
1166 | /*****************************************************************************/ |
1129 | |
|
|
1130 | int inline_size |
|
|
1131 | any_pending (EV_P) |
|
|
1132 | { |
|
|
1133 | int pri; |
|
|
1134 | |
|
|
1135 | for (pri = NUMPRI; pri--; ) |
|
|
1136 | if (pendingcnt [pri]) |
|
|
1137 | return 1; |
|
|
1138 | |
|
|
1139 | return 0; |
|
|
1140 | } |
|
|
1141 | |
1167 | |
1142 | void inline_speed |
1168 | void inline_speed |
1143 | call_pending (EV_P) |
1169 | call_pending (EV_P) |
1144 | { |
1170 | { |
1145 | int pri; |
1171 | int pri; |
… | |
… | |
1236 | for (i = periodiccnt >> 1; i--; ) |
1262 | for (i = periodiccnt >> 1; i--; ) |
1237 | downheap ((WT *)periodics, periodiccnt, i); |
1263 | downheap ((WT *)periodics, periodiccnt, i); |
1238 | } |
1264 | } |
1239 | #endif |
1265 | #endif |
1240 | |
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 | |
1241 | int inline_size |
1290 | int inline_size |
1242 | time_update_monotonic (EV_P) |
1291 | time_update_monotonic (EV_P) |
1243 | { |
1292 | { |
1244 | mn_now = get_clock (); |
1293 | mn_now = get_clock (); |
1245 | |
1294 | |
… | |
… | |
1334 | { |
1383 | { |
1335 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) |
1384 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) |
1336 | ? EVUNLOOP_ONE |
1385 | ? EVUNLOOP_ONE |
1337 | : EVUNLOOP_CANCEL; |
1386 | : EVUNLOOP_CANCEL; |
1338 | |
1387 | |
1339 | while (activecnt) |
1388 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
|
|
1389 | |
|
|
1390 | do |
1340 | { |
1391 | { |
|
|
1392 | #ifndef _WIN32 |
|
|
1393 | if (expect_false (curpid)) /* penalise the forking check even more */ |
|
|
1394 | if (expect_false (getpid () != curpid)) |
|
|
1395 | { |
|
|
1396 | curpid = getpid (); |
|
|
1397 | postfork = 1; |
|
|
1398 | } |
|
|
1399 | #endif |
|
|
1400 | |
1341 | #if EV_FORK_ENABLE |
1401 | #if EV_FORK_ENABLE |
1342 | /* we might have forked, so queue fork handlers */ |
1402 | /* we might have forked, so queue fork handlers */ |
1343 | if (expect_false (postfork)) |
1403 | if (expect_false (postfork)) |
1344 | if (forkcnt) |
1404 | if (forkcnt) |
1345 | { |
1405 | { |
… | |
… | |
1353 | { |
1413 | { |
1354 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1414 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1355 | call_pending (EV_A); |
1415 | call_pending (EV_A); |
1356 | } |
1416 | } |
1357 | |
1417 | |
|
|
1418 | if (expect_false (!activecnt)) |
|
|
1419 | break; |
|
|
1420 | |
1358 | /* we might have forked, so reify kernel state if necessary */ |
1421 | /* we might have forked, so reify kernel state if necessary */ |
1359 | if (expect_false (postfork)) |
1422 | if (expect_false (postfork)) |
1360 | loop_fork (EV_A); |
1423 | loop_fork (EV_A); |
1361 | |
1424 | |
1362 | /* update fd-related kernel structures */ |
1425 | /* update fd-related kernel structures */ |
… | |
… | |
1364 | |
1427 | |
1365 | /* calculate blocking time */ |
1428 | /* calculate blocking time */ |
1366 | { |
1429 | { |
1367 | ev_tstamp block; |
1430 | ev_tstamp block; |
1368 | |
1431 | |
1369 | if (flags & EVLOOP_NONBLOCK || idlecnt) |
1432 | if (expect_false (flags & EVLOOP_NONBLOCK || idleall || !activecnt)) |
1370 | block = 0.; /* do not block at all */ |
1433 | block = 0.; /* do not block at all */ |
1371 | else |
1434 | else |
1372 | { |
1435 | { |
1373 | /* update time to cancel out callback processing overhead */ |
1436 | /* update time to cancel out callback processing overhead */ |
1374 | #if EV_USE_MONOTONIC |
1437 | #if EV_USE_MONOTONIC |
… | |
… | |
1398 | #endif |
1461 | #endif |
1399 | |
1462 | |
1400 | if (expect_false (block < 0.)) block = 0.; |
1463 | if (expect_false (block < 0.)) block = 0.; |
1401 | } |
1464 | } |
1402 | |
1465 | |
|
|
1466 | ++loop_count; |
1403 | backend_poll (EV_A_ block); |
1467 | backend_poll (EV_A_ block); |
1404 | } |
1468 | } |
1405 | |
1469 | |
1406 | /* update ev_rt_now, do magic */ |
1470 | /* update ev_rt_now, do magic */ |
1407 | time_update (EV_A); |
1471 | time_update (EV_A); |
… | |
… | |
1410 | timers_reify (EV_A); /* relative timers called last */ |
1474 | timers_reify (EV_A); /* relative timers called last */ |
1411 | #if EV_PERIODIC_ENABLE |
1475 | #if EV_PERIODIC_ENABLE |
1412 | periodics_reify (EV_A); /* absolute timers called first */ |
1476 | periodics_reify (EV_A); /* absolute timers called first */ |
1413 | #endif |
1477 | #endif |
1414 | |
1478 | |
|
|
1479 | #if EV_IDLE_ENABLE |
1415 | /* queue idle watchers unless other events are pending */ |
1480 | /* queue idle watchers unless other events are pending */ |
1416 | if (idlecnt && !any_pending (EV_A)) |
1481 | idle_reify (EV_A); |
1417 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1482 | #endif |
1418 | |
1483 | |
1419 | /* queue check watchers, to be executed first */ |
1484 | /* queue check watchers, to be executed first */ |
1420 | if (expect_false (checkcnt)) |
1485 | if (expect_false (checkcnt)) |
1421 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1486 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1422 | |
1487 | |
1423 | call_pending (EV_A); |
1488 | call_pending (EV_A); |
1424 | |
1489 | |
1425 | if (expect_false (loop_done)) |
|
|
1426 | break; |
|
|
1427 | } |
1490 | } |
|
|
1491 | while (expect_true (activecnt && !loop_done)); |
1428 | |
1492 | |
1429 | if (loop_done == EVUNLOOP_ONE) |
1493 | if (loop_done == EVUNLOOP_ONE) |
1430 | loop_done = EVUNLOOP_CANCEL; |
1494 | loop_done = EVUNLOOP_CANCEL; |
1431 | } |
1495 | } |
1432 | |
1496 | |
… | |
… | |
1459 | head = &(*head)->next; |
1523 | head = &(*head)->next; |
1460 | } |
1524 | } |
1461 | } |
1525 | } |
1462 | |
1526 | |
1463 | void inline_speed |
1527 | void inline_speed |
1464 | ev_clear_pending (EV_P_ W w) |
1528 | clear_pending (EV_P_ W w) |
1465 | { |
1529 | { |
1466 | if (w->pending) |
1530 | if (w->pending) |
1467 | { |
1531 | { |
1468 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
1532 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
1469 | w->pending = 0; |
1533 | w->pending = 0; |
1470 | } |
1534 | } |
1471 | } |
1535 | } |
1472 | |
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 | |
1473 | void inline_speed |
1564 | void inline_speed |
1474 | ev_start (EV_P_ W w, int active) |
1565 | ev_start (EV_P_ W w, int active) |
1475 | { |
1566 | { |
1476 | if (w->priority < EV_MINPRI) w->priority = EV_MINPRI; |
1567 | pri_adjust (EV_A_ w); |
1477 | if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI; |
|
|
1478 | |
|
|
1479 | w->active = active; |
1568 | w->active = active; |
1480 | ev_ref (EV_A); |
1569 | ev_ref (EV_A); |
1481 | } |
1570 | } |
1482 | |
1571 | |
1483 | void inline_size |
1572 | void inline_size |
… | |
… | |
1507 | } |
1596 | } |
1508 | |
1597 | |
1509 | void |
1598 | void |
1510 | ev_io_stop (EV_P_ ev_io *w) |
1599 | ev_io_stop (EV_P_ ev_io *w) |
1511 | { |
1600 | { |
1512 | ev_clear_pending (EV_A_ (W)w); |
1601 | clear_pending (EV_A_ (W)w); |
1513 | if (expect_false (!ev_is_active (w))) |
1602 | if (expect_false (!ev_is_active (w))) |
1514 | return; |
1603 | return; |
1515 | |
1604 | |
1516 | 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)); |
1517 | |
1606 | |
… | |
… | |
1540 | } |
1629 | } |
1541 | |
1630 | |
1542 | void |
1631 | void |
1543 | ev_timer_stop (EV_P_ ev_timer *w) |
1632 | ev_timer_stop (EV_P_ ev_timer *w) |
1544 | { |
1633 | { |
1545 | ev_clear_pending (EV_A_ (W)w); |
1634 | clear_pending (EV_A_ (W)w); |
1546 | if (expect_false (!ev_is_active (w))) |
1635 | if (expect_false (!ev_is_active (w))) |
1547 | return; |
1636 | return; |
1548 | |
1637 | |
1549 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1638 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1550 | |
1639 | |
… | |
… | |
1608 | } |
1697 | } |
1609 | |
1698 | |
1610 | void |
1699 | void |
1611 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1700 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1612 | { |
1701 | { |
1613 | ev_clear_pending (EV_A_ (W)w); |
1702 | clear_pending (EV_A_ (W)w); |
1614 | if (expect_false (!ev_is_active (w))) |
1703 | if (expect_false (!ev_is_active (w))) |
1615 | return; |
1704 | return; |
1616 | |
1705 | |
1617 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1706 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1618 | |
1707 | |
… | |
… | |
1672 | } |
1761 | } |
1673 | |
1762 | |
1674 | void |
1763 | void |
1675 | ev_signal_stop (EV_P_ ev_signal *w) |
1764 | ev_signal_stop (EV_P_ ev_signal *w) |
1676 | { |
1765 | { |
1677 | ev_clear_pending (EV_A_ (W)w); |
1766 | clear_pending (EV_A_ (W)w); |
1678 | if (expect_false (!ev_is_active (w))) |
1767 | if (expect_false (!ev_is_active (w))) |
1679 | return; |
1768 | return; |
1680 | |
1769 | |
1681 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1770 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1682 | ev_stop (EV_A_ (W)w); |
1771 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1699 | } |
1788 | } |
1700 | |
1789 | |
1701 | void |
1790 | void |
1702 | ev_child_stop (EV_P_ ev_child *w) |
1791 | ev_child_stop (EV_P_ ev_child *w) |
1703 | { |
1792 | { |
1704 | ev_clear_pending (EV_A_ (W)w); |
1793 | clear_pending (EV_A_ (W)w); |
1705 | if (expect_false (!ev_is_active (w))) |
1794 | if (expect_false (!ev_is_active (w))) |
1706 | return; |
1795 | return; |
1707 | |
1796 | |
1708 | 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); |
1709 | ev_stop (EV_A_ (W)w); |
1798 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1945 | } |
2034 | } |
1946 | |
2035 | |
1947 | void |
2036 | void |
1948 | ev_stat_stop (EV_P_ ev_stat *w) |
2037 | ev_stat_stop (EV_P_ ev_stat *w) |
1949 | { |
2038 | { |
1950 | ev_clear_pending (EV_A_ (W)w); |
2039 | clear_pending (EV_A_ (W)w); |
1951 | if (expect_false (!ev_is_active (w))) |
2040 | if (expect_false (!ev_is_active (w))) |
1952 | return; |
2041 | return; |
1953 | |
2042 | |
1954 | #if EV_USE_INOTIFY |
2043 | #if EV_USE_INOTIFY |
1955 | infy_del (EV_A_ w); |
2044 | infy_del (EV_A_ w); |
… | |
… | |
1958 | |
2047 | |
1959 | ev_stop (EV_A_ (W)w); |
2048 | ev_stop (EV_A_ (W)w); |
1960 | } |
2049 | } |
1961 | #endif |
2050 | #endif |
1962 | |
2051 | |
|
|
2052 | #if EV_IDLE_ENABLE |
1963 | void |
2053 | void |
1964 | ev_idle_start (EV_P_ ev_idle *w) |
2054 | ev_idle_start (EV_P_ ev_idle *w) |
1965 | { |
2055 | { |
1966 | if (expect_false (ev_is_active (w))) |
2056 | if (expect_false (ev_is_active (w))) |
1967 | return; |
2057 | return; |
1968 | |
2058 | |
|
|
2059 | pri_adjust (EV_A_ (W)w); |
|
|
2060 | |
|
|
2061 | { |
|
|
2062 | int active = ++idlecnt [ABSPRI (w)]; |
|
|
2063 | |
|
|
2064 | ++idleall; |
1969 | ev_start (EV_A_ (W)w, ++idlecnt); |
2065 | ev_start (EV_A_ (W)w, active); |
|
|
2066 | |
1970 | array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
2067 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
1971 | idles [idlecnt - 1] = w; |
2068 | idles [ABSPRI (w)][active - 1] = w; |
|
|
2069 | } |
1972 | } |
2070 | } |
1973 | |
2071 | |
1974 | void |
2072 | void |
1975 | ev_idle_stop (EV_P_ ev_idle *w) |
2073 | ev_idle_stop (EV_P_ ev_idle *w) |
1976 | { |
2074 | { |
1977 | ev_clear_pending (EV_A_ (W)w); |
2075 | clear_pending (EV_A_ (W)w); |
1978 | if (expect_false (!ev_is_active (w))) |
2076 | if (expect_false (!ev_is_active (w))) |
1979 | return; |
2077 | return; |
1980 | |
2078 | |
1981 | { |
2079 | { |
1982 | int active = ((W)w)->active; |
2080 | int active = ((W)w)->active; |
1983 | idles [active - 1] = idles [--idlecnt]; |
2081 | |
|
|
2082 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
1984 | ((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; |
1985 | } |
2087 | } |
1986 | |
|
|
1987 | ev_stop (EV_A_ (W)w); |
|
|
1988 | } |
2088 | } |
|
|
2089 | #endif |
1989 | |
2090 | |
1990 | void |
2091 | void |
1991 | ev_prepare_start (EV_P_ ev_prepare *w) |
2092 | ev_prepare_start (EV_P_ ev_prepare *w) |
1992 | { |
2093 | { |
1993 | if (expect_false (ev_is_active (w))) |
2094 | if (expect_false (ev_is_active (w))) |
… | |
… | |
1999 | } |
2100 | } |
2000 | |
2101 | |
2001 | void |
2102 | void |
2002 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2103 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2003 | { |
2104 | { |
2004 | ev_clear_pending (EV_A_ (W)w); |
2105 | clear_pending (EV_A_ (W)w); |
2005 | if (expect_false (!ev_is_active (w))) |
2106 | if (expect_false (!ev_is_active (w))) |
2006 | return; |
2107 | return; |
2007 | |
2108 | |
2008 | { |
2109 | { |
2009 | int active = ((W)w)->active; |
2110 | int active = ((W)w)->active; |
… | |
… | |
2026 | } |
2127 | } |
2027 | |
2128 | |
2028 | void |
2129 | void |
2029 | ev_check_stop (EV_P_ ev_check *w) |
2130 | ev_check_stop (EV_P_ ev_check *w) |
2030 | { |
2131 | { |
2031 | ev_clear_pending (EV_A_ (W)w); |
2132 | clear_pending (EV_A_ (W)w); |
2032 | if (expect_false (!ev_is_active (w))) |
2133 | if (expect_false (!ev_is_active (w))) |
2033 | return; |
2134 | return; |
2034 | |
2135 | |
2035 | { |
2136 | { |
2036 | int active = ((W)w)->active; |
2137 | int active = ((W)w)->active; |
… | |
… | |
2078 | } |
2179 | } |
2079 | |
2180 | |
2080 | void |
2181 | void |
2081 | ev_embed_stop (EV_P_ ev_embed *w) |
2182 | ev_embed_stop (EV_P_ ev_embed *w) |
2082 | { |
2183 | { |
2083 | ev_clear_pending (EV_A_ (W)w); |
2184 | clear_pending (EV_A_ (W)w); |
2084 | if (expect_false (!ev_is_active (w))) |
2185 | if (expect_false (!ev_is_active (w))) |
2085 | return; |
2186 | return; |
2086 | |
2187 | |
2087 | ev_io_stop (EV_A_ &w->io); |
2188 | ev_io_stop (EV_A_ &w->io); |
2088 | |
2189 | |
… | |
… | |
2103 | } |
2204 | } |
2104 | |
2205 | |
2105 | void |
2206 | void |
2106 | ev_fork_stop (EV_P_ ev_fork *w) |
2207 | ev_fork_stop (EV_P_ ev_fork *w) |
2107 | { |
2208 | { |
2108 | ev_clear_pending (EV_A_ (W)w); |
2209 | clear_pending (EV_A_ (W)w); |
2109 | if (expect_false (!ev_is_active (w))) |
2210 | if (expect_false (!ev_is_active (w))) |
2110 | return; |
2211 | return; |
2111 | |
2212 | |
2112 | { |
2213 | { |
2113 | int active = ((W)w)->active; |
2214 | int active = ((W)w)->active; |