… | |
… | |
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 | /*****************************************************************************/ |
… | |
… | |
485 | } |
507 | } |
486 | |
508 | |
487 | void |
509 | void |
488 | ev_feed_fd_event (EV_P_ int fd, int revents) |
510 | ev_feed_fd_event (EV_P_ int fd, int revents) |
489 | { |
511 | { |
|
|
512 | if (fd >= 0 && fd < anfdmax) |
490 | fd_event (EV_A_ fd, revents); |
513 | fd_event (EV_A_ fd, revents); |
491 | } |
514 | } |
492 | |
515 | |
493 | void inline_size |
516 | void inline_size |
494 | fd_reify (EV_P) |
517 | fd_reify (EV_P) |
495 | { |
518 | { |
… | |
… | |
764 | ev_child *w; |
787 | ev_child *w; |
765 | |
788 | |
766 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
789 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
767 | if (w->pid == pid || !w->pid) |
790 | if (w->pid == pid || !w->pid) |
768 | { |
791 | { |
769 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
792 | ev_set_priority (w, ev_priority (sw)); /* need to do it *now* */ |
770 | w->rpid = pid; |
793 | w->rpid = pid; |
771 | w->rstatus = status; |
794 | w->rstatus = status; |
772 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
795 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
773 | } |
796 | } |
774 | } |
797 | } |
775 | |
798 | |
776 | #ifndef WCONTINUED |
799 | #ifndef WCONTINUED |
… | |
… | |
886 | ev_backend (EV_P) |
909 | ev_backend (EV_P) |
887 | { |
910 | { |
888 | return backend; |
911 | return backend; |
889 | } |
912 | } |
890 | |
913 | |
|
|
914 | unsigned int |
|
|
915 | ev_loop_count (EV_P) |
|
|
916 | { |
|
|
917 | return loop_count; |
|
|
918 | } |
|
|
919 | |
891 | static void noinline |
920 | static void noinline |
892 | loop_init (EV_P_ unsigned int flags) |
921 | loop_init (EV_P_ unsigned int flags) |
893 | { |
922 | { |
894 | if (!backend) |
923 | if (!backend) |
895 | { |
924 | { |
… | |
… | |
904 | ev_rt_now = ev_time (); |
933 | ev_rt_now = ev_time (); |
905 | mn_now = get_clock (); |
934 | mn_now = get_clock (); |
906 | now_floor = mn_now; |
935 | now_floor = mn_now; |
907 | rtmn_diff = ev_rt_now - mn_now; |
936 | rtmn_diff = ev_rt_now - mn_now; |
908 | |
937 | |
|
|
938 | /* pid check not overridable via env */ |
|
|
939 | #ifndef _WIN32 |
|
|
940 | if (flags & EVFLAG_FORKCHECK) |
|
|
941 | curpid = getpid (); |
|
|
942 | #endif |
|
|
943 | |
909 | if (!(flags & EVFLAG_NOENV) |
944 | if (!(flags & EVFLAG_NOENV) |
910 | && !enable_secure () |
945 | && !enable_secure () |
911 | && getenv ("LIBEV_FLAGS")) |
946 | && getenv ("LIBEV_FLAGS")) |
912 | flags = atoi (getenv ("LIBEV_FLAGS")); |
947 | flags = atoi (getenv ("LIBEV_FLAGS")); |
913 | |
948 | |
… | |
… | |
969 | #if EV_USE_SELECT |
1004 | #if EV_USE_SELECT |
970 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
1005 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
971 | #endif |
1006 | #endif |
972 | |
1007 | |
973 | for (i = NUMPRI; i--; ) |
1008 | for (i = NUMPRI; i--; ) |
|
|
1009 | { |
974 | array_free (pending, [i]); |
1010 | array_free (pending, [i]); |
|
|
1011 | #if EV_IDLE_ENABLE |
|
|
1012 | array_free (idle, [i]); |
|
|
1013 | #endif |
|
|
1014 | } |
975 | |
1015 | |
976 | /* have to use the microsoft-never-gets-it-right macro */ |
1016 | /* have to use the microsoft-never-gets-it-right macro */ |
977 | array_free (fdchange, EMPTY0); |
1017 | array_free (fdchange, EMPTY); |
978 | array_free (timer, EMPTY0); |
1018 | array_free (timer, EMPTY); |
979 | #if EV_PERIODIC_ENABLE |
1019 | #if EV_PERIODIC_ENABLE |
980 | array_free (periodic, EMPTY0); |
1020 | array_free (periodic, EMPTY); |
981 | #endif |
1021 | #endif |
982 | array_free (idle, EMPTY0); |
|
|
983 | array_free (prepare, EMPTY0); |
1022 | array_free (prepare, EMPTY); |
984 | array_free (check, EMPTY0); |
1023 | array_free (check, EMPTY); |
985 | |
1024 | |
986 | backend = 0; |
1025 | backend = 0; |
987 | } |
1026 | } |
988 | |
1027 | |
989 | void inline_size infy_fork (EV_P); |
1028 | void inline_size infy_fork (EV_P); |
… | |
… | |
1125 | postfork = 1; |
1164 | postfork = 1; |
1126 | } |
1165 | } |
1127 | |
1166 | |
1128 | /*****************************************************************************/ |
1167 | /*****************************************************************************/ |
1129 | |
1168 | |
1130 | int inline_size |
1169 | void |
1131 | any_pending (EV_P) |
1170 | ev_invoke (EV_P_ void *w, int revents) |
1132 | { |
1171 | { |
1133 | int pri; |
1172 | EV_CB_INVOKE ((W)w, revents); |
1134 | |
|
|
1135 | for (pri = NUMPRI; pri--; ) |
|
|
1136 | if (pendingcnt [pri]) |
|
|
1137 | return 1; |
|
|
1138 | |
|
|
1139 | return 0; |
|
|
1140 | } |
1173 | } |
1141 | |
1174 | |
1142 | void inline_speed |
1175 | void inline_speed |
1143 | call_pending (EV_P) |
1176 | call_pending (EV_P) |
1144 | { |
1177 | { |
… | |
… | |
1236 | for (i = periodiccnt >> 1; i--; ) |
1269 | for (i = periodiccnt >> 1; i--; ) |
1237 | downheap ((WT *)periodics, periodiccnt, i); |
1270 | downheap ((WT *)periodics, periodiccnt, i); |
1238 | } |
1271 | } |
1239 | #endif |
1272 | #endif |
1240 | |
1273 | |
|
|
1274 | #if EV_IDLE_ENABLE |
|
|
1275 | void inline_size |
|
|
1276 | idle_reify (EV_P) |
|
|
1277 | { |
|
|
1278 | if (expect_false (idleall)) |
|
|
1279 | { |
|
|
1280 | int pri; |
|
|
1281 | |
|
|
1282 | for (pri = NUMPRI; pri--; ) |
|
|
1283 | { |
|
|
1284 | if (pendingcnt [pri]) |
|
|
1285 | break; |
|
|
1286 | |
|
|
1287 | if (idlecnt [pri]) |
|
|
1288 | { |
|
|
1289 | queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE); |
|
|
1290 | break; |
|
|
1291 | } |
|
|
1292 | } |
|
|
1293 | } |
|
|
1294 | } |
|
|
1295 | #endif |
|
|
1296 | |
1241 | int inline_size |
1297 | int inline_size |
1242 | time_update_monotonic (EV_P) |
1298 | time_update_monotonic (EV_P) |
1243 | { |
1299 | { |
1244 | mn_now = get_clock (); |
1300 | mn_now = get_clock (); |
1245 | |
1301 | |
… | |
… | |
1334 | { |
1390 | { |
1335 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) |
1391 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) |
1336 | ? EVUNLOOP_ONE |
1392 | ? EVUNLOOP_ONE |
1337 | : EVUNLOOP_CANCEL; |
1393 | : EVUNLOOP_CANCEL; |
1338 | |
1394 | |
1339 | while (activecnt) |
1395 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
|
|
1396 | |
|
|
1397 | do |
1340 | { |
1398 | { |
|
|
1399 | #ifndef _WIN32 |
|
|
1400 | if (expect_false (curpid)) /* penalise the forking check even more */ |
|
|
1401 | if (expect_false (getpid () != curpid)) |
|
|
1402 | { |
|
|
1403 | curpid = getpid (); |
|
|
1404 | postfork = 1; |
|
|
1405 | } |
|
|
1406 | #endif |
|
|
1407 | |
1341 | #if EV_FORK_ENABLE |
1408 | #if EV_FORK_ENABLE |
1342 | /* we might have forked, so queue fork handlers */ |
1409 | /* we might have forked, so queue fork handlers */ |
1343 | if (expect_false (postfork)) |
1410 | if (expect_false (postfork)) |
1344 | if (forkcnt) |
1411 | if (forkcnt) |
1345 | { |
1412 | { |
… | |
… | |
1353 | { |
1420 | { |
1354 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1421 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1355 | call_pending (EV_A); |
1422 | call_pending (EV_A); |
1356 | } |
1423 | } |
1357 | |
1424 | |
|
|
1425 | if (expect_false (!activecnt)) |
|
|
1426 | break; |
|
|
1427 | |
1358 | /* we might have forked, so reify kernel state if necessary */ |
1428 | /* we might have forked, so reify kernel state if necessary */ |
1359 | if (expect_false (postfork)) |
1429 | if (expect_false (postfork)) |
1360 | loop_fork (EV_A); |
1430 | loop_fork (EV_A); |
1361 | |
1431 | |
1362 | /* update fd-related kernel structures */ |
1432 | /* update fd-related kernel structures */ |
… | |
… | |
1364 | |
1434 | |
1365 | /* calculate blocking time */ |
1435 | /* calculate blocking time */ |
1366 | { |
1436 | { |
1367 | ev_tstamp block; |
1437 | ev_tstamp block; |
1368 | |
1438 | |
1369 | if (flags & EVLOOP_NONBLOCK || idlecnt) |
1439 | if (expect_false (flags & EVLOOP_NONBLOCK || idleall || !activecnt)) |
1370 | block = 0.; /* do not block at all */ |
1440 | block = 0.; /* do not block at all */ |
1371 | else |
1441 | else |
1372 | { |
1442 | { |
1373 | /* update time to cancel out callback processing overhead */ |
1443 | /* update time to cancel out callback processing overhead */ |
1374 | #if EV_USE_MONOTONIC |
1444 | #if EV_USE_MONOTONIC |
… | |
… | |
1398 | #endif |
1468 | #endif |
1399 | |
1469 | |
1400 | if (expect_false (block < 0.)) block = 0.; |
1470 | if (expect_false (block < 0.)) block = 0.; |
1401 | } |
1471 | } |
1402 | |
1472 | |
|
|
1473 | ++loop_count; |
1403 | backend_poll (EV_A_ block); |
1474 | backend_poll (EV_A_ block); |
1404 | } |
1475 | } |
1405 | |
1476 | |
1406 | /* update ev_rt_now, do magic */ |
1477 | /* update ev_rt_now, do magic */ |
1407 | time_update (EV_A); |
1478 | time_update (EV_A); |
… | |
… | |
1410 | timers_reify (EV_A); /* relative timers called last */ |
1481 | timers_reify (EV_A); /* relative timers called last */ |
1411 | #if EV_PERIODIC_ENABLE |
1482 | #if EV_PERIODIC_ENABLE |
1412 | periodics_reify (EV_A); /* absolute timers called first */ |
1483 | periodics_reify (EV_A); /* absolute timers called first */ |
1413 | #endif |
1484 | #endif |
1414 | |
1485 | |
|
|
1486 | #if EV_IDLE_ENABLE |
1415 | /* queue idle watchers unless other events are pending */ |
1487 | /* queue idle watchers unless other events are pending */ |
1416 | if (idlecnt && !any_pending (EV_A)) |
1488 | idle_reify (EV_A); |
1417 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1489 | #endif |
1418 | |
1490 | |
1419 | /* queue check watchers, to be executed first */ |
1491 | /* queue check watchers, to be executed first */ |
1420 | if (expect_false (checkcnt)) |
1492 | if (expect_false (checkcnt)) |
1421 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1493 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1422 | |
1494 | |
1423 | call_pending (EV_A); |
1495 | call_pending (EV_A); |
1424 | |
1496 | |
1425 | if (expect_false (loop_done)) |
|
|
1426 | break; |
|
|
1427 | } |
1497 | } |
|
|
1498 | while (expect_true (activecnt && !loop_done)); |
1428 | |
1499 | |
1429 | if (loop_done == EVUNLOOP_ONE) |
1500 | if (loop_done == EVUNLOOP_ONE) |
1430 | loop_done = EVUNLOOP_CANCEL; |
1501 | loop_done = EVUNLOOP_CANCEL; |
1431 | } |
1502 | } |
1432 | |
1503 | |
… | |
… | |
1459 | head = &(*head)->next; |
1530 | head = &(*head)->next; |
1460 | } |
1531 | } |
1461 | } |
1532 | } |
1462 | |
1533 | |
1463 | void inline_speed |
1534 | void inline_speed |
1464 | ev_clear_pending (EV_P_ W w) |
1535 | clear_pending (EV_P_ W w) |
1465 | { |
1536 | { |
1466 | if (w->pending) |
1537 | if (w->pending) |
1467 | { |
1538 | { |
1468 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
1539 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
1469 | w->pending = 0; |
1540 | w->pending = 0; |
1470 | } |
1541 | } |
1471 | } |
1542 | } |
1472 | |
1543 | |
|
|
1544 | int |
|
|
1545 | ev_clear_pending (EV_P_ void *w) |
|
|
1546 | { |
|
|
1547 | W w_ = (W)w; |
|
|
1548 | int pending = w_->pending; |
|
|
1549 | |
|
|
1550 | if (!pending) |
|
|
1551 | return 0; |
|
|
1552 | |
|
|
1553 | w_->pending = 0; |
|
|
1554 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
|
|
1555 | p->w = 0; |
|
|
1556 | |
|
|
1557 | return p->events; |
|
|
1558 | } |
|
|
1559 | |
|
|
1560 | void inline_size |
|
|
1561 | pri_adjust (EV_P_ W w) |
|
|
1562 | { |
|
|
1563 | int pri = w->priority; |
|
|
1564 | pri = pri < EV_MINPRI ? EV_MINPRI : pri; |
|
|
1565 | pri = pri > EV_MAXPRI ? EV_MAXPRI : pri; |
|
|
1566 | w->priority = pri; |
|
|
1567 | } |
|
|
1568 | |
1473 | void inline_speed |
1569 | void inline_speed |
1474 | ev_start (EV_P_ W w, int active) |
1570 | ev_start (EV_P_ W w, int active) |
1475 | { |
1571 | { |
1476 | if (w->priority < EV_MINPRI) w->priority = EV_MINPRI; |
1572 | pri_adjust (EV_A_ w); |
1477 | if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI; |
|
|
1478 | |
|
|
1479 | w->active = active; |
1573 | w->active = active; |
1480 | ev_ref (EV_A); |
1574 | ev_ref (EV_A); |
1481 | } |
1575 | } |
1482 | |
1576 | |
1483 | void inline_size |
1577 | void inline_size |
… | |
… | |
1507 | } |
1601 | } |
1508 | |
1602 | |
1509 | void |
1603 | void |
1510 | ev_io_stop (EV_P_ ev_io *w) |
1604 | ev_io_stop (EV_P_ ev_io *w) |
1511 | { |
1605 | { |
1512 | ev_clear_pending (EV_A_ (W)w); |
1606 | clear_pending (EV_A_ (W)w); |
1513 | if (expect_false (!ev_is_active (w))) |
1607 | if (expect_false (!ev_is_active (w))) |
1514 | return; |
1608 | return; |
1515 | |
1609 | |
1516 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1610 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1517 | |
1611 | |
… | |
… | |
1540 | } |
1634 | } |
1541 | |
1635 | |
1542 | void |
1636 | void |
1543 | ev_timer_stop (EV_P_ ev_timer *w) |
1637 | ev_timer_stop (EV_P_ ev_timer *w) |
1544 | { |
1638 | { |
1545 | ev_clear_pending (EV_A_ (W)w); |
1639 | clear_pending (EV_A_ (W)w); |
1546 | if (expect_false (!ev_is_active (w))) |
1640 | if (expect_false (!ev_is_active (w))) |
1547 | return; |
1641 | return; |
1548 | |
1642 | |
1549 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1643 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1550 | |
1644 | |
… | |
… | |
1608 | } |
1702 | } |
1609 | |
1703 | |
1610 | void |
1704 | void |
1611 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1705 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1612 | { |
1706 | { |
1613 | ev_clear_pending (EV_A_ (W)w); |
1707 | clear_pending (EV_A_ (W)w); |
1614 | if (expect_false (!ev_is_active (w))) |
1708 | if (expect_false (!ev_is_active (w))) |
1615 | return; |
1709 | return; |
1616 | |
1710 | |
1617 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1711 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1618 | |
1712 | |
… | |
… | |
1672 | } |
1766 | } |
1673 | |
1767 | |
1674 | void |
1768 | void |
1675 | ev_signal_stop (EV_P_ ev_signal *w) |
1769 | ev_signal_stop (EV_P_ ev_signal *w) |
1676 | { |
1770 | { |
1677 | ev_clear_pending (EV_A_ (W)w); |
1771 | clear_pending (EV_A_ (W)w); |
1678 | if (expect_false (!ev_is_active (w))) |
1772 | if (expect_false (!ev_is_active (w))) |
1679 | return; |
1773 | return; |
1680 | |
1774 | |
1681 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1775 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1682 | ev_stop (EV_A_ (W)w); |
1776 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1699 | } |
1793 | } |
1700 | |
1794 | |
1701 | void |
1795 | void |
1702 | ev_child_stop (EV_P_ ev_child *w) |
1796 | ev_child_stop (EV_P_ ev_child *w) |
1703 | { |
1797 | { |
1704 | ev_clear_pending (EV_A_ (W)w); |
1798 | clear_pending (EV_A_ (W)w); |
1705 | if (expect_false (!ev_is_active (w))) |
1799 | if (expect_false (!ev_is_active (w))) |
1706 | return; |
1800 | return; |
1707 | |
1801 | |
1708 | wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1802 | wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1709 | ev_stop (EV_A_ (W)w); |
1803 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1945 | } |
2039 | } |
1946 | |
2040 | |
1947 | void |
2041 | void |
1948 | ev_stat_stop (EV_P_ ev_stat *w) |
2042 | ev_stat_stop (EV_P_ ev_stat *w) |
1949 | { |
2043 | { |
1950 | ev_clear_pending (EV_A_ (W)w); |
2044 | clear_pending (EV_A_ (W)w); |
1951 | if (expect_false (!ev_is_active (w))) |
2045 | if (expect_false (!ev_is_active (w))) |
1952 | return; |
2046 | return; |
1953 | |
2047 | |
1954 | #if EV_USE_INOTIFY |
2048 | #if EV_USE_INOTIFY |
1955 | infy_del (EV_A_ w); |
2049 | infy_del (EV_A_ w); |
… | |
… | |
1958 | |
2052 | |
1959 | ev_stop (EV_A_ (W)w); |
2053 | ev_stop (EV_A_ (W)w); |
1960 | } |
2054 | } |
1961 | #endif |
2055 | #endif |
1962 | |
2056 | |
|
|
2057 | #if EV_IDLE_ENABLE |
1963 | void |
2058 | void |
1964 | ev_idle_start (EV_P_ ev_idle *w) |
2059 | ev_idle_start (EV_P_ ev_idle *w) |
1965 | { |
2060 | { |
1966 | if (expect_false (ev_is_active (w))) |
2061 | if (expect_false (ev_is_active (w))) |
1967 | return; |
2062 | return; |
1968 | |
2063 | |
|
|
2064 | pri_adjust (EV_A_ (W)w); |
|
|
2065 | |
|
|
2066 | { |
|
|
2067 | int active = ++idlecnt [ABSPRI (w)]; |
|
|
2068 | |
|
|
2069 | ++idleall; |
1969 | ev_start (EV_A_ (W)w, ++idlecnt); |
2070 | ev_start (EV_A_ (W)w, active); |
|
|
2071 | |
1970 | array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
2072 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
1971 | idles [idlecnt - 1] = w; |
2073 | idles [ABSPRI (w)][active - 1] = w; |
|
|
2074 | } |
1972 | } |
2075 | } |
1973 | |
2076 | |
1974 | void |
2077 | void |
1975 | ev_idle_stop (EV_P_ ev_idle *w) |
2078 | ev_idle_stop (EV_P_ ev_idle *w) |
1976 | { |
2079 | { |
1977 | ev_clear_pending (EV_A_ (W)w); |
2080 | clear_pending (EV_A_ (W)w); |
1978 | if (expect_false (!ev_is_active (w))) |
2081 | if (expect_false (!ev_is_active (w))) |
1979 | return; |
2082 | return; |
1980 | |
2083 | |
1981 | { |
2084 | { |
1982 | int active = ((W)w)->active; |
2085 | int active = ((W)w)->active; |
1983 | idles [active - 1] = idles [--idlecnt]; |
2086 | |
|
|
2087 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
1984 | ((W)idles [active - 1])->active = active; |
2088 | ((W)idles [ABSPRI (w)][active - 1])->active = active; |
|
|
2089 | |
|
|
2090 | ev_stop (EV_A_ (W)w); |
|
|
2091 | --idleall; |
1985 | } |
2092 | } |
1986 | |
|
|
1987 | ev_stop (EV_A_ (W)w); |
|
|
1988 | } |
2093 | } |
|
|
2094 | #endif |
1989 | |
2095 | |
1990 | void |
2096 | void |
1991 | ev_prepare_start (EV_P_ ev_prepare *w) |
2097 | ev_prepare_start (EV_P_ ev_prepare *w) |
1992 | { |
2098 | { |
1993 | if (expect_false (ev_is_active (w))) |
2099 | if (expect_false (ev_is_active (w))) |
… | |
… | |
1999 | } |
2105 | } |
2000 | |
2106 | |
2001 | void |
2107 | void |
2002 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2108 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2003 | { |
2109 | { |
2004 | ev_clear_pending (EV_A_ (W)w); |
2110 | clear_pending (EV_A_ (W)w); |
2005 | if (expect_false (!ev_is_active (w))) |
2111 | if (expect_false (!ev_is_active (w))) |
2006 | return; |
2112 | return; |
2007 | |
2113 | |
2008 | { |
2114 | { |
2009 | int active = ((W)w)->active; |
2115 | int active = ((W)w)->active; |
… | |
… | |
2026 | } |
2132 | } |
2027 | |
2133 | |
2028 | void |
2134 | void |
2029 | ev_check_stop (EV_P_ ev_check *w) |
2135 | ev_check_stop (EV_P_ ev_check *w) |
2030 | { |
2136 | { |
2031 | ev_clear_pending (EV_A_ (W)w); |
2137 | clear_pending (EV_A_ (W)w); |
2032 | if (expect_false (!ev_is_active (w))) |
2138 | if (expect_false (!ev_is_active (w))) |
2033 | return; |
2139 | return; |
2034 | |
2140 | |
2035 | { |
2141 | { |
2036 | int active = ((W)w)->active; |
2142 | int active = ((W)w)->active; |
… | |
… | |
2078 | } |
2184 | } |
2079 | |
2185 | |
2080 | void |
2186 | void |
2081 | ev_embed_stop (EV_P_ ev_embed *w) |
2187 | ev_embed_stop (EV_P_ ev_embed *w) |
2082 | { |
2188 | { |
2083 | ev_clear_pending (EV_A_ (W)w); |
2189 | clear_pending (EV_A_ (W)w); |
2084 | if (expect_false (!ev_is_active (w))) |
2190 | if (expect_false (!ev_is_active (w))) |
2085 | return; |
2191 | return; |
2086 | |
2192 | |
2087 | ev_io_stop (EV_A_ &w->io); |
2193 | ev_io_stop (EV_A_ &w->io); |
2088 | |
2194 | |
… | |
… | |
2103 | } |
2209 | } |
2104 | |
2210 | |
2105 | void |
2211 | void |
2106 | ev_fork_stop (EV_P_ ev_fork *w) |
2212 | ev_fork_stop (EV_P_ ev_fork *w) |
2107 | { |
2213 | { |
2108 | ev_clear_pending (EV_A_ (W)w); |
2214 | clear_pending (EV_A_ (W)w); |
2109 | if (expect_false (!ev_is_active (w))) |
2215 | if (expect_false (!ev_is_active (w))) |
2110 | return; |
2216 | return; |
2111 | |
2217 | |
2112 | { |
2218 | { |
2113 | int active = ((W)w)->active; |
2219 | int active = ((W)w)->active; |