… | |
… | |
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; |
… | |
… | |
417 | } |
418 | } |
418 | |
419 | |
419 | return ncur; |
420 | return ncur; |
420 | } |
421 | } |
421 | |
422 | |
422 | inline_speed void * |
423 | static noinline void * |
423 | array_realloc (int elem, void *base, int *cur, int cnt) |
424 | array_realloc (int elem, void *base, int *cur, int cnt) |
424 | { |
425 | { |
425 | *cur = array_nextsize (elem, *cur, cnt); |
426 | *cur = array_nextsize (elem, *cur, cnt); |
426 | return ev_realloc (base, elem * *cur); |
427 | return ev_realloc (base, elem * *cur); |
427 | } |
428 | } |
… | |
… | |
452 | |
453 | |
453 | void noinline |
454 | void noinline |
454 | ev_feed_event (EV_P_ void *w, int revents) |
455 | ev_feed_event (EV_P_ void *w, int revents) |
455 | { |
456 | { |
456 | W w_ = (W)w; |
457 | W w_ = (W)w; |
|
|
458 | int pri = ABSPRI (w_); |
457 | |
459 | |
458 | if (expect_false (w_->pending)) |
460 | if (expect_false (w_->pending)) |
|
|
461 | pendings [pri][w_->pending - 1].events |= revents; |
|
|
462 | else |
459 | { |
463 | { |
|
|
464 | w_->pending = ++pendingcnt [pri]; |
|
|
465 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
|
|
466 | pendings [pri][w_->pending - 1].w = w_; |
460 | pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; |
467 | pendings [pri][w_->pending - 1].events = revents; |
461 | return; |
|
|
462 | } |
468 | } |
463 | |
|
|
464 | w_->pending = ++pendingcnt [ABSPRI (w_)]; |
|
|
465 | array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); |
|
|
466 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
|
|
467 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
|
|
468 | } |
469 | } |
469 | |
470 | |
470 | void inline_size |
471 | void inline_size |
471 | queue_events (EV_P_ W *events, int eventcnt, int type) |
472 | queue_events (EV_P_ W *events, int eventcnt, int type) |
472 | { |
473 | { |
… | |
… | |
507 | } |
508 | } |
508 | |
509 | |
509 | void |
510 | void |
510 | ev_feed_fd_event (EV_P_ int fd, int revents) |
511 | ev_feed_fd_event (EV_P_ int fd, int revents) |
511 | { |
512 | { |
|
|
513 | if (fd >= 0 && fd < anfdmax) |
512 | fd_event (EV_A_ fd, revents); |
514 | fd_event (EV_A_ fd, revents); |
513 | } |
515 | } |
514 | |
516 | |
515 | void inline_size |
517 | void inline_size |
516 | fd_reify (EV_P) |
518 | fd_reify (EV_P) |
517 | { |
519 | { |
… | |
… | |
747 | for (signum = signalmax; signum--; ) |
749 | for (signum = signalmax; signum--; ) |
748 | if (signals [signum].gotsig) |
750 | if (signals [signum].gotsig) |
749 | ev_feed_signal_event (EV_A_ signum + 1); |
751 | ev_feed_signal_event (EV_A_ signum + 1); |
750 | } |
752 | } |
751 | |
753 | |
752 | void inline_size |
754 | void inline_speed |
753 | fd_intern (int fd) |
755 | fd_intern (int fd) |
754 | { |
756 | { |
755 | #ifdef _WIN32 |
757 | #ifdef _WIN32 |
756 | int arg = 1; |
758 | int arg = 1; |
757 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
759 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
… | |
… | |
786 | ev_child *w; |
788 | ev_child *w; |
787 | |
789 | |
788 | 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) |
789 | if (w->pid == pid || !w->pid) |
791 | if (w->pid == pid || !w->pid) |
790 | { |
792 | { |
791 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
793 | ev_set_priority (w, ev_priority (sw)); /* need to do it *now* */ |
792 | w->rpid = pid; |
794 | w->rpid = pid; |
793 | w->rstatus = status; |
795 | w->rstatus = status; |
794 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
796 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
795 | } |
797 | } |
796 | } |
798 | } |
797 | |
799 | |
798 | #ifndef WCONTINUED |
800 | #ifndef WCONTINUED |
… | |
… | |
1003 | #if EV_USE_SELECT |
1005 | #if EV_USE_SELECT |
1004 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
1006 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
1005 | #endif |
1007 | #endif |
1006 | |
1008 | |
1007 | for (i = NUMPRI; i--; ) |
1009 | for (i = NUMPRI; i--; ) |
|
|
1010 | { |
1008 | array_free (pending, [i]); |
1011 | array_free (pending, [i]); |
|
|
1012 | #if EV_IDLE_ENABLE |
|
|
1013 | array_free (idle, [i]); |
|
|
1014 | #endif |
|
|
1015 | } |
1009 | |
1016 | |
1010 | /* have to use the microsoft-never-gets-it-right macro */ |
1017 | /* have to use the microsoft-never-gets-it-right macro */ |
1011 | array_free (fdchange, EMPTY0); |
1018 | array_free (fdchange, EMPTY); |
1012 | array_free (timer, EMPTY0); |
1019 | array_free (timer, EMPTY); |
1013 | #if EV_PERIODIC_ENABLE |
1020 | #if EV_PERIODIC_ENABLE |
1014 | array_free (periodic, EMPTY0); |
1021 | array_free (periodic, EMPTY); |
1015 | #endif |
1022 | #endif |
1016 | array_free (idle, EMPTY0); |
|
|
1017 | array_free (prepare, EMPTY0); |
1023 | array_free (prepare, EMPTY); |
1018 | array_free (check, EMPTY0); |
1024 | array_free (check, EMPTY); |
1019 | |
1025 | |
1020 | backend = 0; |
1026 | backend = 0; |
1021 | } |
1027 | } |
1022 | |
1028 | |
1023 | void inline_size infy_fork (EV_P); |
1029 | void inline_size infy_fork (EV_P); |
… | |
… | |
1159 | postfork = 1; |
1165 | postfork = 1; |
1160 | } |
1166 | } |
1161 | |
1167 | |
1162 | /*****************************************************************************/ |
1168 | /*****************************************************************************/ |
1163 | |
1169 | |
1164 | int inline_size |
1170 | void |
1165 | any_pending (EV_P) |
1171 | ev_invoke (EV_P_ void *w, int revents) |
1166 | { |
1172 | { |
1167 | int pri; |
1173 | EV_CB_INVOKE ((W)w, revents); |
1168 | |
|
|
1169 | for (pri = NUMPRI; pri--; ) |
|
|
1170 | if (pendingcnt [pri]) |
|
|
1171 | return 1; |
|
|
1172 | |
|
|
1173 | return 0; |
|
|
1174 | } |
1174 | } |
1175 | |
1175 | |
1176 | void inline_speed |
1176 | void inline_speed |
1177 | call_pending (EV_P) |
1177 | call_pending (EV_P) |
1178 | { |
1178 | { |
… | |
… | |
1270 | for (i = periodiccnt >> 1; i--; ) |
1270 | for (i = periodiccnt >> 1; i--; ) |
1271 | downheap ((WT *)periodics, periodiccnt, i); |
1271 | downheap ((WT *)periodics, periodiccnt, i); |
1272 | } |
1272 | } |
1273 | #endif |
1273 | #endif |
1274 | |
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 | |
1275 | int inline_size |
1298 | int inline_size |
1276 | time_update_monotonic (EV_P) |
1299 | time_update_monotonic (EV_P) |
1277 | { |
1300 | { |
1278 | mn_now = get_clock (); |
1301 | mn_now = get_clock (); |
1279 | |
1302 | |
… | |
… | |
1391 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
1414 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
1392 | call_pending (EV_A); |
1415 | call_pending (EV_A); |
1393 | } |
1416 | } |
1394 | #endif |
1417 | #endif |
1395 | |
1418 | |
1396 | /* queue check watchers (and execute them) */ |
1419 | /* queue prepare watchers (and execute them) */ |
1397 | if (expect_false (preparecnt)) |
1420 | if (expect_false (preparecnt)) |
1398 | { |
1421 | { |
1399 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1422 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1400 | call_pending (EV_A); |
1423 | call_pending (EV_A); |
1401 | } |
1424 | } |
… | |
… | |
1412 | |
1435 | |
1413 | /* calculate blocking time */ |
1436 | /* calculate blocking time */ |
1414 | { |
1437 | { |
1415 | ev_tstamp block; |
1438 | ev_tstamp block; |
1416 | |
1439 | |
1417 | if (expect_false (flags & EVLOOP_NONBLOCK || idlecnt || !activecnt)) |
1440 | if (expect_false (flags & EVLOOP_NONBLOCK || idleall || !activecnt)) |
1418 | block = 0.; /* do not block at all */ |
1441 | block = 0.; /* do not block at all */ |
1419 | else |
1442 | else |
1420 | { |
1443 | { |
1421 | /* update time to cancel out callback processing overhead */ |
1444 | /* update time to cancel out callback processing overhead */ |
1422 | #if EV_USE_MONOTONIC |
1445 | #if EV_USE_MONOTONIC |
… | |
… | |
1459 | timers_reify (EV_A); /* relative timers called last */ |
1482 | timers_reify (EV_A); /* relative timers called last */ |
1460 | #if EV_PERIODIC_ENABLE |
1483 | #if EV_PERIODIC_ENABLE |
1461 | periodics_reify (EV_A); /* absolute timers called first */ |
1484 | periodics_reify (EV_A); /* absolute timers called first */ |
1462 | #endif |
1485 | #endif |
1463 | |
1486 | |
|
|
1487 | #if EV_IDLE_ENABLE |
1464 | /* queue idle watchers unless other events are pending */ |
1488 | /* queue idle watchers unless other events are pending */ |
1465 | if (idlecnt && !any_pending (EV_A)) |
1489 | idle_reify (EV_A); |
1466 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1490 | #endif |
1467 | |
1491 | |
1468 | /* queue check watchers, to be executed first */ |
1492 | /* queue check watchers, to be executed first */ |
1469 | if (expect_false (checkcnt)) |
1493 | if (expect_false (checkcnt)) |
1470 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1494 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1471 | |
1495 | |
… | |
… | |
1507 | head = &(*head)->next; |
1531 | head = &(*head)->next; |
1508 | } |
1532 | } |
1509 | } |
1533 | } |
1510 | |
1534 | |
1511 | void inline_speed |
1535 | void inline_speed |
1512 | ev_clear_pending (EV_P_ W w) |
1536 | clear_pending (EV_P_ W w) |
1513 | { |
1537 | { |
1514 | if (w->pending) |
1538 | if (w->pending) |
1515 | { |
1539 | { |
1516 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
1540 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
1517 | w->pending = 0; |
1541 | w->pending = 0; |
1518 | } |
1542 | } |
1519 | } |
1543 | } |
1520 | |
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 (expect_true (pending)) |
|
|
1552 | { |
|
|
1553 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
|
|
1554 | w_->pending = 0; |
|
|
1555 | p->w = 0; |
|
|
1556 | return p->events; |
|
|
1557 | } |
|
|
1558 | else |
|
|
1559 | return 0; |
|
|
1560 | } |
|
|
1561 | |
|
|
1562 | void inline_size |
|
|
1563 | pri_adjust (EV_P_ W w) |
|
|
1564 | { |
|
|
1565 | int pri = w->priority; |
|
|
1566 | pri = pri < EV_MINPRI ? EV_MINPRI : pri; |
|
|
1567 | pri = pri > EV_MAXPRI ? EV_MAXPRI : pri; |
|
|
1568 | w->priority = pri; |
|
|
1569 | } |
|
|
1570 | |
1521 | void inline_speed |
1571 | void inline_speed |
1522 | ev_start (EV_P_ W w, int active) |
1572 | ev_start (EV_P_ W w, int active) |
1523 | { |
1573 | { |
1524 | if (w->priority < EV_MINPRI) w->priority = EV_MINPRI; |
1574 | pri_adjust (EV_A_ w); |
1525 | if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI; |
|
|
1526 | |
|
|
1527 | w->active = active; |
1575 | w->active = active; |
1528 | ev_ref (EV_A); |
1576 | ev_ref (EV_A); |
1529 | } |
1577 | } |
1530 | |
1578 | |
1531 | void inline_size |
1579 | void inline_size |
… | |
… | |
1535 | w->active = 0; |
1583 | w->active = 0; |
1536 | } |
1584 | } |
1537 | |
1585 | |
1538 | /*****************************************************************************/ |
1586 | /*****************************************************************************/ |
1539 | |
1587 | |
1540 | void |
1588 | void noinline |
1541 | ev_io_start (EV_P_ ev_io *w) |
1589 | ev_io_start (EV_P_ ev_io *w) |
1542 | { |
1590 | { |
1543 | int fd = w->fd; |
1591 | int fd = w->fd; |
1544 | |
1592 | |
1545 | if (expect_false (ev_is_active (w))) |
1593 | if (expect_false (ev_is_active (w))) |
… | |
… | |
1552 | wlist_add ((WL *)&anfds[fd].head, (WL)w); |
1600 | wlist_add ((WL *)&anfds[fd].head, (WL)w); |
1553 | |
1601 | |
1554 | fd_change (EV_A_ fd); |
1602 | fd_change (EV_A_ fd); |
1555 | } |
1603 | } |
1556 | |
1604 | |
1557 | void |
1605 | void noinline |
1558 | ev_io_stop (EV_P_ ev_io *w) |
1606 | ev_io_stop (EV_P_ ev_io *w) |
1559 | { |
1607 | { |
1560 | ev_clear_pending (EV_A_ (W)w); |
1608 | clear_pending (EV_A_ (W)w); |
1561 | if (expect_false (!ev_is_active (w))) |
1609 | if (expect_false (!ev_is_active (w))) |
1562 | return; |
1610 | return; |
1563 | |
1611 | |
1564 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1612 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1565 | |
1613 | |
… | |
… | |
1567 | ev_stop (EV_A_ (W)w); |
1615 | ev_stop (EV_A_ (W)w); |
1568 | |
1616 | |
1569 | fd_change (EV_A_ w->fd); |
1617 | fd_change (EV_A_ w->fd); |
1570 | } |
1618 | } |
1571 | |
1619 | |
1572 | void |
1620 | void noinline |
1573 | ev_timer_start (EV_P_ ev_timer *w) |
1621 | ev_timer_start (EV_P_ ev_timer *w) |
1574 | { |
1622 | { |
1575 | if (expect_false (ev_is_active (w))) |
1623 | if (expect_false (ev_is_active (w))) |
1576 | return; |
1624 | return; |
1577 | |
1625 | |
… | |
… | |
1585 | upheap ((WT *)timers, timercnt - 1); |
1633 | upheap ((WT *)timers, timercnt - 1); |
1586 | |
1634 | |
1587 | /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ |
1635 | /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ |
1588 | } |
1636 | } |
1589 | |
1637 | |
1590 | void |
1638 | void noinline |
1591 | ev_timer_stop (EV_P_ ev_timer *w) |
1639 | ev_timer_stop (EV_P_ ev_timer *w) |
1592 | { |
1640 | { |
1593 | ev_clear_pending (EV_A_ (W)w); |
1641 | clear_pending (EV_A_ (W)w); |
1594 | if (expect_false (!ev_is_active (w))) |
1642 | if (expect_false (!ev_is_active (w))) |
1595 | return; |
1643 | return; |
1596 | |
1644 | |
1597 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1645 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1598 | |
1646 | |
… | |
… | |
1609 | ((WT)w)->at -= mn_now; |
1657 | ((WT)w)->at -= mn_now; |
1610 | |
1658 | |
1611 | ev_stop (EV_A_ (W)w); |
1659 | ev_stop (EV_A_ (W)w); |
1612 | } |
1660 | } |
1613 | |
1661 | |
1614 | void |
1662 | void noinline |
1615 | ev_timer_again (EV_P_ ev_timer *w) |
1663 | ev_timer_again (EV_P_ ev_timer *w) |
1616 | { |
1664 | { |
1617 | if (ev_is_active (w)) |
1665 | if (ev_is_active (w)) |
1618 | { |
1666 | { |
1619 | if (w->repeat) |
1667 | if (w->repeat) |
… | |
… | |
1630 | ev_timer_start (EV_A_ w); |
1678 | ev_timer_start (EV_A_ w); |
1631 | } |
1679 | } |
1632 | } |
1680 | } |
1633 | |
1681 | |
1634 | #if EV_PERIODIC_ENABLE |
1682 | #if EV_PERIODIC_ENABLE |
1635 | void |
1683 | void noinline |
1636 | ev_periodic_start (EV_P_ ev_periodic *w) |
1684 | ev_periodic_start (EV_P_ ev_periodic *w) |
1637 | { |
1685 | { |
1638 | if (expect_false (ev_is_active (w))) |
1686 | if (expect_false (ev_is_active (w))) |
1639 | return; |
1687 | return; |
1640 | |
1688 | |
… | |
… | |
1653 | upheap ((WT *)periodics, periodiccnt - 1); |
1701 | upheap ((WT *)periodics, periodiccnt - 1); |
1654 | |
1702 | |
1655 | /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ |
1703 | /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ |
1656 | } |
1704 | } |
1657 | |
1705 | |
1658 | void |
1706 | void noinline |
1659 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1707 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1660 | { |
1708 | { |
1661 | ev_clear_pending (EV_A_ (W)w); |
1709 | clear_pending (EV_A_ (W)w); |
1662 | if (expect_false (!ev_is_active (w))) |
1710 | if (expect_false (!ev_is_active (w))) |
1663 | return; |
1711 | return; |
1664 | |
1712 | |
1665 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1713 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1666 | |
1714 | |
… | |
… | |
1675 | } |
1723 | } |
1676 | |
1724 | |
1677 | ev_stop (EV_A_ (W)w); |
1725 | ev_stop (EV_A_ (W)w); |
1678 | } |
1726 | } |
1679 | |
1727 | |
1680 | void |
1728 | void noinline |
1681 | ev_periodic_again (EV_P_ ev_periodic *w) |
1729 | ev_periodic_again (EV_P_ ev_periodic *w) |
1682 | { |
1730 | { |
1683 | /* TODO: use adjustheap and recalculation */ |
1731 | /* TODO: use adjustheap and recalculation */ |
1684 | ev_periodic_stop (EV_A_ w); |
1732 | ev_periodic_stop (EV_A_ w); |
1685 | ev_periodic_start (EV_A_ w); |
1733 | ev_periodic_start (EV_A_ w); |
… | |
… | |
1688 | |
1736 | |
1689 | #ifndef SA_RESTART |
1737 | #ifndef SA_RESTART |
1690 | # define SA_RESTART 0 |
1738 | # define SA_RESTART 0 |
1691 | #endif |
1739 | #endif |
1692 | |
1740 | |
1693 | void |
1741 | void noinline |
1694 | ev_signal_start (EV_P_ ev_signal *w) |
1742 | ev_signal_start (EV_P_ ev_signal *w) |
1695 | { |
1743 | { |
1696 | #if EV_MULTIPLICITY |
1744 | #if EV_MULTIPLICITY |
1697 | assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1745 | assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1698 | #endif |
1746 | #endif |
… | |
… | |
1717 | sigaction (w->signum, &sa, 0); |
1765 | sigaction (w->signum, &sa, 0); |
1718 | #endif |
1766 | #endif |
1719 | } |
1767 | } |
1720 | } |
1768 | } |
1721 | |
1769 | |
1722 | void |
1770 | void noinline |
1723 | ev_signal_stop (EV_P_ ev_signal *w) |
1771 | ev_signal_stop (EV_P_ ev_signal *w) |
1724 | { |
1772 | { |
1725 | ev_clear_pending (EV_A_ (W)w); |
1773 | clear_pending (EV_A_ (W)w); |
1726 | if (expect_false (!ev_is_active (w))) |
1774 | if (expect_false (!ev_is_active (w))) |
1727 | return; |
1775 | return; |
1728 | |
1776 | |
1729 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1777 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1730 | ev_stop (EV_A_ (W)w); |
1778 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1747 | } |
1795 | } |
1748 | |
1796 | |
1749 | void |
1797 | void |
1750 | ev_child_stop (EV_P_ ev_child *w) |
1798 | ev_child_stop (EV_P_ ev_child *w) |
1751 | { |
1799 | { |
1752 | ev_clear_pending (EV_A_ (W)w); |
1800 | clear_pending (EV_A_ (W)w); |
1753 | if (expect_false (!ev_is_active (w))) |
1801 | if (expect_false (!ev_is_active (w))) |
1754 | return; |
1802 | return; |
1755 | |
1803 | |
1756 | wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1804 | wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1757 | ev_stop (EV_A_ (W)w); |
1805 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1993 | } |
2041 | } |
1994 | |
2042 | |
1995 | void |
2043 | void |
1996 | ev_stat_stop (EV_P_ ev_stat *w) |
2044 | ev_stat_stop (EV_P_ ev_stat *w) |
1997 | { |
2045 | { |
1998 | ev_clear_pending (EV_A_ (W)w); |
2046 | clear_pending (EV_A_ (W)w); |
1999 | if (expect_false (!ev_is_active (w))) |
2047 | if (expect_false (!ev_is_active (w))) |
2000 | return; |
2048 | return; |
2001 | |
2049 | |
2002 | #if EV_USE_INOTIFY |
2050 | #if EV_USE_INOTIFY |
2003 | infy_del (EV_A_ w); |
2051 | infy_del (EV_A_ w); |
… | |
… | |
2006 | |
2054 | |
2007 | ev_stop (EV_A_ (W)w); |
2055 | ev_stop (EV_A_ (W)w); |
2008 | } |
2056 | } |
2009 | #endif |
2057 | #endif |
2010 | |
2058 | |
|
|
2059 | #if EV_IDLE_ENABLE |
2011 | void |
2060 | void |
2012 | ev_idle_start (EV_P_ ev_idle *w) |
2061 | ev_idle_start (EV_P_ ev_idle *w) |
2013 | { |
2062 | { |
2014 | if (expect_false (ev_is_active (w))) |
2063 | if (expect_false (ev_is_active (w))) |
2015 | return; |
2064 | return; |
2016 | |
2065 | |
|
|
2066 | pri_adjust (EV_A_ (W)w); |
|
|
2067 | |
|
|
2068 | { |
|
|
2069 | int active = ++idlecnt [ABSPRI (w)]; |
|
|
2070 | |
|
|
2071 | ++idleall; |
2017 | ev_start (EV_A_ (W)w, ++idlecnt); |
2072 | ev_start (EV_A_ (W)w, active); |
|
|
2073 | |
2018 | array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
2074 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
2019 | idles [idlecnt - 1] = w; |
2075 | idles [ABSPRI (w)][active - 1] = w; |
|
|
2076 | } |
2020 | } |
2077 | } |
2021 | |
2078 | |
2022 | void |
2079 | void |
2023 | ev_idle_stop (EV_P_ ev_idle *w) |
2080 | ev_idle_stop (EV_P_ ev_idle *w) |
2024 | { |
2081 | { |
2025 | ev_clear_pending (EV_A_ (W)w); |
2082 | clear_pending (EV_A_ (W)w); |
2026 | if (expect_false (!ev_is_active (w))) |
2083 | if (expect_false (!ev_is_active (w))) |
2027 | return; |
2084 | return; |
2028 | |
2085 | |
2029 | { |
2086 | { |
2030 | int active = ((W)w)->active; |
2087 | int active = ((W)w)->active; |
2031 | idles [active - 1] = idles [--idlecnt]; |
2088 | |
|
|
2089 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
2032 | ((W)idles [active - 1])->active = active; |
2090 | ((W)idles [ABSPRI (w)][active - 1])->active = active; |
|
|
2091 | |
|
|
2092 | ev_stop (EV_A_ (W)w); |
|
|
2093 | --idleall; |
2033 | } |
2094 | } |
2034 | |
|
|
2035 | ev_stop (EV_A_ (W)w); |
|
|
2036 | } |
2095 | } |
|
|
2096 | #endif |
2037 | |
2097 | |
2038 | void |
2098 | void |
2039 | ev_prepare_start (EV_P_ ev_prepare *w) |
2099 | ev_prepare_start (EV_P_ ev_prepare *w) |
2040 | { |
2100 | { |
2041 | if (expect_false (ev_is_active (w))) |
2101 | if (expect_false (ev_is_active (w))) |
… | |
… | |
2047 | } |
2107 | } |
2048 | |
2108 | |
2049 | void |
2109 | void |
2050 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2110 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2051 | { |
2111 | { |
2052 | ev_clear_pending (EV_A_ (W)w); |
2112 | clear_pending (EV_A_ (W)w); |
2053 | if (expect_false (!ev_is_active (w))) |
2113 | if (expect_false (!ev_is_active (w))) |
2054 | return; |
2114 | return; |
2055 | |
2115 | |
2056 | { |
2116 | { |
2057 | int active = ((W)w)->active; |
2117 | int active = ((W)w)->active; |
… | |
… | |
2074 | } |
2134 | } |
2075 | |
2135 | |
2076 | void |
2136 | void |
2077 | ev_check_stop (EV_P_ ev_check *w) |
2137 | ev_check_stop (EV_P_ ev_check *w) |
2078 | { |
2138 | { |
2079 | ev_clear_pending (EV_A_ (W)w); |
2139 | clear_pending (EV_A_ (W)w); |
2080 | if (expect_false (!ev_is_active (w))) |
2140 | if (expect_false (!ev_is_active (w))) |
2081 | return; |
2141 | return; |
2082 | |
2142 | |
2083 | { |
2143 | { |
2084 | int active = ((W)w)->active; |
2144 | int active = ((W)w)->active; |
… | |
… | |
2126 | } |
2186 | } |
2127 | |
2187 | |
2128 | void |
2188 | void |
2129 | ev_embed_stop (EV_P_ ev_embed *w) |
2189 | ev_embed_stop (EV_P_ ev_embed *w) |
2130 | { |
2190 | { |
2131 | ev_clear_pending (EV_A_ (W)w); |
2191 | clear_pending (EV_A_ (W)w); |
2132 | if (expect_false (!ev_is_active (w))) |
2192 | if (expect_false (!ev_is_active (w))) |
2133 | return; |
2193 | return; |
2134 | |
2194 | |
2135 | ev_io_stop (EV_A_ &w->io); |
2195 | ev_io_stop (EV_A_ &w->io); |
2136 | |
2196 | |
… | |
… | |
2151 | } |
2211 | } |
2152 | |
2212 | |
2153 | void |
2213 | void |
2154 | ev_fork_stop (EV_P_ ev_fork *w) |
2214 | ev_fork_stop (EV_P_ ev_fork *w) |
2155 | { |
2215 | { |
2156 | ev_clear_pending (EV_A_ (W)w); |
2216 | clear_pending (EV_A_ (W)w); |
2157 | if (expect_false (!ev_is_active (w))) |
2217 | if (expect_false (!ev_is_active (w))) |
2158 | return; |
2218 | return; |
2159 | |
2219 | |
2160 | { |
2220 | { |
2161 | int active = ((W)w)->active; |
2221 | int active = ((W)w)->active; |