… | |
… | |
202 | #define ABSPRI(w) ((w)->priority - EV_MINPRI) |
202 | #define ABSPRI(w) ((w)->priority - EV_MINPRI) |
203 | |
203 | |
204 | #define EMPTY0 /* required for microsofts broken pseudo-c compiler */ |
204 | #define EMPTY0 /* required for microsofts broken pseudo-c compiler */ |
205 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
205 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
206 | |
206 | |
207 | typedef struct ev_watcher *W; |
207 | typedef ev_watcher *W; |
208 | typedef struct ev_watcher_list *WL; |
208 | typedef ev_watcher_list *WL; |
209 | typedef struct ev_watcher_time *WT; |
209 | typedef ev_watcher_time *WT; |
210 | |
210 | |
211 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
211 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
212 | |
212 | |
213 | #ifdef _WIN32 |
213 | #ifdef _WIN32 |
214 | # include "ev_win32.c" |
214 | # include "ev_win32.c" |
… | |
… | |
397 | { |
397 | { |
398 | pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; |
398 | pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; |
399 | return; |
399 | return; |
400 | } |
400 | } |
401 | |
401 | |
402 | if (expect_false (!w_->cb)) |
|
|
403 | return; |
|
|
404 | |
|
|
405 | w_->pending = ++pendingcnt [ABSPRI (w_)]; |
402 | w_->pending = ++pendingcnt [ABSPRI (w_)]; |
406 | array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); |
403 | array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); |
407 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
404 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
408 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
405 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
409 | } |
406 | } |
… | |
… | |
419 | |
416 | |
420 | inline void |
417 | inline void |
421 | fd_event (EV_P_ int fd, int revents) |
418 | fd_event (EV_P_ int fd, int revents) |
422 | { |
419 | { |
423 | ANFD *anfd = anfds + fd; |
420 | ANFD *anfd = anfds + fd; |
424 | struct ev_io *w; |
421 | ev_io *w; |
425 | |
422 | |
426 | for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) |
423 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
427 | { |
424 | { |
428 | int ev = w->events & revents; |
425 | int ev = w->events & revents; |
429 | |
426 | |
430 | if (ev) |
427 | if (ev) |
431 | ev_feed_event (EV_A_ (W)w, ev); |
428 | ev_feed_event (EV_A_ (W)w, ev); |
… | |
… | |
447 | |
444 | |
448 | for (i = 0; i < fdchangecnt; ++i) |
445 | for (i = 0; i < fdchangecnt; ++i) |
449 | { |
446 | { |
450 | int fd = fdchanges [i]; |
447 | int fd = fdchanges [i]; |
451 | ANFD *anfd = anfds + fd; |
448 | ANFD *anfd = anfds + fd; |
452 | struct ev_io *w; |
449 | ev_io *w; |
453 | |
450 | |
454 | int events = 0; |
451 | int events = 0; |
455 | |
452 | |
456 | for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) |
453 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
457 | events |= w->events; |
454 | events |= w->events; |
458 | |
455 | |
459 | #if EV_SELECT_IS_WINSOCKET |
456 | #if EV_SELECT_IS_WINSOCKET |
460 | if (events) |
457 | if (events) |
461 | { |
458 | { |
… | |
… | |
488 | } |
485 | } |
489 | |
486 | |
490 | static void |
487 | static void |
491 | fd_kill (EV_P_ int fd) |
488 | fd_kill (EV_P_ int fd) |
492 | { |
489 | { |
493 | struct ev_io *w; |
490 | ev_io *w; |
494 | |
491 | |
495 | while ((w = (struct ev_io *)anfds [fd].head)) |
492 | while ((w = (ev_io *)anfds [fd].head)) |
496 | { |
493 | { |
497 | ev_io_stop (EV_A_ w); |
494 | ev_io_stop (EV_A_ w); |
498 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
495 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
499 | } |
496 | } |
500 | } |
497 | } |
… | |
… | |
611 | static ANSIG *signals; |
608 | static ANSIG *signals; |
612 | static int signalmax; |
609 | static int signalmax; |
613 | |
610 | |
614 | static int sigpipe [2]; |
611 | static int sigpipe [2]; |
615 | static sig_atomic_t volatile gotsig; |
612 | static sig_atomic_t volatile gotsig; |
616 | static struct ev_io sigev; |
613 | static ev_io sigev; |
617 | |
614 | |
618 | static void |
615 | static void |
619 | signals_init (ANSIG *base, int count) |
616 | signals_init (ANSIG *base, int count) |
620 | { |
617 | { |
621 | while (count--) |
618 | while (count--) |
… | |
… | |
664 | for (w = signals [signum].head; w; w = w->next) |
661 | for (w = signals [signum].head; w; w = w->next) |
665 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
662 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
666 | } |
663 | } |
667 | |
664 | |
668 | static void |
665 | static void |
669 | sigcb (EV_P_ struct ev_io *iow, int revents) |
666 | sigcb (EV_P_ ev_io *iow, int revents) |
670 | { |
667 | { |
671 | int signum; |
668 | int signum; |
672 | |
669 | |
673 | read (sigpipe [0], &revents, 1); |
670 | read (sigpipe [0], &revents, 1); |
674 | gotsig = 0; |
671 | gotsig = 0; |
… | |
… | |
701 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
698 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
702 | } |
699 | } |
703 | |
700 | |
704 | /*****************************************************************************/ |
701 | /*****************************************************************************/ |
705 | |
702 | |
706 | static struct ev_child *childs [PID_HASHSIZE]; |
703 | static ev_child *childs [PID_HASHSIZE]; |
707 | |
704 | |
708 | #ifndef _WIN32 |
705 | #ifndef _WIN32 |
709 | |
706 | |
710 | static struct ev_signal childev; |
707 | static ev_signal childev; |
711 | |
708 | |
712 | #ifndef WCONTINUED |
709 | #ifndef WCONTINUED |
713 | # define WCONTINUED 0 |
710 | # define WCONTINUED 0 |
714 | #endif |
711 | #endif |
715 | |
712 | |
716 | static void |
713 | static void |
717 | child_reap (EV_P_ struct ev_signal *sw, int chain, int pid, int status) |
714 | child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) |
718 | { |
715 | { |
719 | struct ev_child *w; |
716 | ev_child *w; |
720 | |
717 | |
721 | for (w = (struct ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (struct ev_child *)((WL)w)->next) |
718 | for (w = (ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
722 | if (w->pid == pid || !w->pid) |
719 | if (w->pid == pid || !w->pid) |
723 | { |
720 | { |
724 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
721 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
725 | w->rpid = pid; |
722 | w->rpid = pid; |
726 | w->rstatus = status; |
723 | w->rstatus = status; |
727 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
724 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
728 | } |
725 | } |
729 | } |
726 | } |
730 | |
727 | |
731 | static void |
728 | static void |
732 | childcb (EV_P_ struct ev_signal *sw, int revents) |
729 | childcb (EV_P_ ev_signal *sw, int revents) |
733 | { |
730 | { |
734 | int pid, status; |
731 | int pid, status; |
735 | |
732 | |
736 | if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
733 | if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
737 | { |
734 | { |
… | |
… | |
1088 | inline void |
1085 | inline void |
1089 | timers_reify (EV_P) |
1086 | timers_reify (EV_P) |
1090 | { |
1087 | { |
1091 | while (timercnt && ((WT)timers [0])->at <= mn_now) |
1088 | while (timercnt && ((WT)timers [0])->at <= mn_now) |
1092 | { |
1089 | { |
1093 | struct ev_timer *w = timers [0]; |
1090 | ev_timer *w = timers [0]; |
1094 | |
1091 | |
1095 | assert (("inactive timer on timer heap detected", ev_is_active (w))); |
1092 | assert (("inactive timer on timer heap detected", ev_is_active (w))); |
1096 | |
1093 | |
1097 | /* first reschedule or stop timer */ |
1094 | /* first reschedule or stop timer */ |
1098 | if (w->repeat) |
1095 | if (w->repeat) |
… | |
… | |
1116 | inline void |
1113 | inline void |
1117 | periodics_reify (EV_P) |
1114 | periodics_reify (EV_P) |
1118 | { |
1115 | { |
1119 | while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) |
1116 | while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) |
1120 | { |
1117 | { |
1121 | struct ev_periodic *w = periodics [0]; |
1118 | ev_periodic *w = periodics [0]; |
1122 | |
1119 | |
1123 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
1120 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
1124 | |
1121 | |
1125 | /* first reschedule or stop timer */ |
1122 | /* first reschedule or stop timer */ |
1126 | if (w->reschedule_cb) |
1123 | if (w->reschedule_cb) |
… | |
… | |
1148 | int i; |
1145 | int i; |
1149 | |
1146 | |
1150 | /* adjust periodics after time jump */ |
1147 | /* adjust periodics after time jump */ |
1151 | for (i = 0; i < periodiccnt; ++i) |
1148 | for (i = 0; i < periodiccnt; ++i) |
1152 | { |
1149 | { |
1153 | struct ev_periodic *w = periodics [i]; |
1150 | ev_periodic *w = periodics [i]; |
1154 | |
1151 | |
1155 | if (w->reschedule_cb) |
1152 | if (w->reschedule_cb) |
1156 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1153 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1157 | else if (w->interval) |
1154 | else if (w->interval) |
1158 | ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1155 | ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; |
… | |
… | |
1396 | } |
1393 | } |
1397 | |
1394 | |
1398 | /*****************************************************************************/ |
1395 | /*****************************************************************************/ |
1399 | |
1396 | |
1400 | void |
1397 | void |
1401 | ev_io_start (EV_P_ struct ev_io *w) |
1398 | ev_io_start (EV_P_ ev_io *w) |
1402 | { |
1399 | { |
1403 | int fd = w->fd; |
1400 | int fd = w->fd; |
1404 | |
1401 | |
1405 | if (expect_false (ev_is_active (w))) |
1402 | if (expect_false (ev_is_active (w))) |
1406 | return; |
1403 | return; |
… | |
… | |
1413 | |
1410 | |
1414 | fd_change (EV_A_ fd); |
1411 | fd_change (EV_A_ fd); |
1415 | } |
1412 | } |
1416 | |
1413 | |
1417 | void |
1414 | void |
1418 | ev_io_stop (EV_P_ struct ev_io *w) |
1415 | ev_io_stop (EV_P_ ev_io *w) |
1419 | { |
1416 | { |
1420 | ev_clear_pending (EV_A_ (W)w); |
1417 | ev_clear_pending (EV_A_ (W)w); |
1421 | if (expect_false (!ev_is_active (w))) |
1418 | if (expect_false (!ev_is_active (w))) |
1422 | return; |
1419 | return; |
1423 | |
1420 | |
… | |
… | |
1428 | |
1425 | |
1429 | fd_change (EV_A_ w->fd); |
1426 | fd_change (EV_A_ w->fd); |
1430 | } |
1427 | } |
1431 | |
1428 | |
1432 | void |
1429 | void |
1433 | ev_timer_start (EV_P_ struct ev_timer *w) |
1430 | ev_timer_start (EV_P_ ev_timer *w) |
1434 | { |
1431 | { |
1435 | if (expect_false (ev_is_active (w))) |
1432 | if (expect_false (ev_is_active (w))) |
1436 | return; |
1433 | return; |
1437 | |
1434 | |
1438 | ((WT)w)->at += mn_now; |
1435 | ((WT)w)->at += mn_now; |
1439 | |
1436 | |
1440 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1437 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1441 | |
1438 | |
1442 | ev_start (EV_A_ (W)w, ++timercnt); |
1439 | ev_start (EV_A_ (W)w, ++timercnt); |
1443 | array_needsize (struct ev_timer *, timers, timermax, timercnt, EMPTY2); |
1440 | array_needsize (ev_timer *, timers, timermax, timercnt, EMPTY2); |
1444 | timers [timercnt - 1] = w; |
1441 | timers [timercnt - 1] = w; |
1445 | upheap ((WT *)timers, timercnt - 1); |
1442 | upheap ((WT *)timers, timercnt - 1); |
1446 | |
1443 | |
1447 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1444 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1448 | } |
1445 | } |
1449 | |
1446 | |
1450 | void |
1447 | void |
1451 | ev_timer_stop (EV_P_ struct ev_timer *w) |
1448 | ev_timer_stop (EV_P_ ev_timer *w) |
1452 | { |
1449 | { |
1453 | ev_clear_pending (EV_A_ (W)w); |
1450 | ev_clear_pending (EV_A_ (W)w); |
1454 | if (expect_false (!ev_is_active (w))) |
1451 | if (expect_false (!ev_is_active (w))) |
1455 | return; |
1452 | return; |
1456 | |
1453 | |
… | |
… | |
1466 | |
1463 | |
1467 | ev_stop (EV_A_ (W)w); |
1464 | ev_stop (EV_A_ (W)w); |
1468 | } |
1465 | } |
1469 | |
1466 | |
1470 | void |
1467 | void |
1471 | ev_timer_again (EV_P_ struct ev_timer *w) |
1468 | ev_timer_again (EV_P_ ev_timer *w) |
1472 | { |
1469 | { |
1473 | if (ev_is_active (w)) |
1470 | if (ev_is_active (w)) |
1474 | { |
1471 | { |
1475 | if (w->repeat) |
1472 | if (w->repeat) |
1476 | { |
1473 | { |
… | |
… | |
1487 | } |
1484 | } |
1488 | } |
1485 | } |
1489 | |
1486 | |
1490 | #if EV_PERIODICS |
1487 | #if EV_PERIODICS |
1491 | void |
1488 | void |
1492 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1489 | ev_periodic_start (EV_P_ ev_periodic *w) |
1493 | { |
1490 | { |
1494 | if (expect_false (ev_is_active (w))) |
1491 | if (expect_false (ev_is_active (w))) |
1495 | return; |
1492 | return; |
1496 | |
1493 | |
1497 | if (w->reschedule_cb) |
1494 | if (w->reschedule_cb) |
… | |
… | |
1502 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1499 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1503 | ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1500 | ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1504 | } |
1501 | } |
1505 | |
1502 | |
1506 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1503 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1507 | array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); |
1504 | array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); |
1508 | periodics [periodiccnt - 1] = w; |
1505 | periodics [periodiccnt - 1] = w; |
1509 | upheap ((WT *)periodics, periodiccnt - 1); |
1506 | upheap ((WT *)periodics, periodiccnt - 1); |
1510 | |
1507 | |
1511 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1508 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1512 | } |
1509 | } |
1513 | |
1510 | |
1514 | void |
1511 | void |
1515 | ev_periodic_stop (EV_P_ struct ev_periodic *w) |
1512 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1516 | { |
1513 | { |
1517 | ev_clear_pending (EV_A_ (W)w); |
1514 | ev_clear_pending (EV_A_ (W)w); |
1518 | if (expect_false (!ev_is_active (w))) |
1515 | if (expect_false (!ev_is_active (w))) |
1519 | return; |
1516 | return; |
1520 | |
1517 | |
… | |
… | |
1528 | |
1525 | |
1529 | ev_stop (EV_A_ (W)w); |
1526 | ev_stop (EV_A_ (W)w); |
1530 | } |
1527 | } |
1531 | |
1528 | |
1532 | void |
1529 | void |
1533 | ev_periodic_again (EV_P_ struct ev_periodic *w) |
1530 | ev_periodic_again (EV_P_ ev_periodic *w) |
1534 | { |
1531 | { |
1535 | /* TODO: use adjustheap and recalculation */ |
1532 | /* TODO: use adjustheap and recalculation */ |
1536 | ev_periodic_stop (EV_A_ w); |
1533 | ev_periodic_stop (EV_A_ w); |
1537 | ev_periodic_start (EV_A_ w); |
1534 | ev_periodic_start (EV_A_ w); |
1538 | } |
1535 | } |
1539 | #endif |
1536 | #endif |
1540 | |
1537 | |
1541 | void |
1538 | void |
1542 | ev_idle_start (EV_P_ struct ev_idle *w) |
1539 | ev_idle_start (EV_P_ ev_idle *w) |
1543 | { |
1540 | { |
1544 | if (expect_false (ev_is_active (w))) |
1541 | if (expect_false (ev_is_active (w))) |
1545 | return; |
1542 | return; |
1546 | |
1543 | |
1547 | ev_start (EV_A_ (W)w, ++idlecnt); |
1544 | ev_start (EV_A_ (W)w, ++idlecnt); |
1548 | array_needsize (struct ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
1545 | array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
1549 | idles [idlecnt - 1] = w; |
1546 | idles [idlecnt - 1] = w; |
1550 | } |
1547 | } |
1551 | |
1548 | |
1552 | void |
1549 | void |
1553 | ev_idle_stop (EV_P_ struct ev_idle *w) |
1550 | ev_idle_stop (EV_P_ ev_idle *w) |
1554 | { |
1551 | { |
1555 | ev_clear_pending (EV_A_ (W)w); |
1552 | ev_clear_pending (EV_A_ (W)w); |
1556 | if (expect_false (!ev_is_active (w))) |
1553 | if (expect_false (!ev_is_active (w))) |
1557 | return; |
1554 | return; |
1558 | |
1555 | |
1559 | idles [((W)w)->active - 1] = idles [--idlecnt]; |
1556 | idles [((W)w)->active - 1] = idles [--idlecnt]; |
1560 | ev_stop (EV_A_ (W)w); |
1557 | ev_stop (EV_A_ (W)w); |
1561 | } |
1558 | } |
1562 | |
1559 | |
1563 | void |
1560 | void |
1564 | ev_prepare_start (EV_P_ struct ev_prepare *w) |
1561 | ev_prepare_start (EV_P_ ev_prepare *w) |
1565 | { |
1562 | { |
1566 | if (expect_false (ev_is_active (w))) |
1563 | if (expect_false (ev_is_active (w))) |
1567 | return; |
1564 | return; |
1568 | |
1565 | |
1569 | ev_start (EV_A_ (W)w, ++preparecnt); |
1566 | ev_start (EV_A_ (W)w, ++preparecnt); |
1570 | array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
1567 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
1571 | prepares [preparecnt - 1] = w; |
1568 | prepares [preparecnt - 1] = w; |
1572 | } |
1569 | } |
1573 | |
1570 | |
1574 | void |
1571 | void |
1575 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
1572 | ev_prepare_stop (EV_P_ ev_prepare *w) |
1576 | { |
1573 | { |
1577 | ev_clear_pending (EV_A_ (W)w); |
1574 | ev_clear_pending (EV_A_ (W)w); |
1578 | if (expect_false (!ev_is_active (w))) |
1575 | if (expect_false (!ev_is_active (w))) |
1579 | return; |
1576 | return; |
1580 | |
1577 | |
1581 | prepares [((W)w)->active - 1] = prepares [--preparecnt]; |
1578 | prepares [((W)w)->active - 1] = prepares [--preparecnt]; |
1582 | ev_stop (EV_A_ (W)w); |
1579 | ev_stop (EV_A_ (W)w); |
1583 | } |
1580 | } |
1584 | |
1581 | |
1585 | void |
1582 | void |
1586 | ev_check_start (EV_P_ struct ev_check *w) |
1583 | ev_check_start (EV_P_ ev_check *w) |
1587 | { |
1584 | { |
1588 | if (expect_false (ev_is_active (w))) |
1585 | if (expect_false (ev_is_active (w))) |
1589 | return; |
1586 | return; |
1590 | |
1587 | |
1591 | ev_start (EV_A_ (W)w, ++checkcnt); |
1588 | ev_start (EV_A_ (W)w, ++checkcnt); |
1592 | array_needsize (struct ev_check *, checks, checkmax, checkcnt, EMPTY2); |
1589 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
1593 | checks [checkcnt - 1] = w; |
1590 | checks [checkcnt - 1] = w; |
1594 | } |
1591 | } |
1595 | |
1592 | |
1596 | void |
1593 | void |
1597 | ev_check_stop (EV_P_ struct ev_check *w) |
1594 | ev_check_stop (EV_P_ ev_check *w) |
1598 | { |
1595 | { |
1599 | ev_clear_pending (EV_A_ (W)w); |
1596 | ev_clear_pending (EV_A_ (W)w); |
1600 | if (expect_false (!ev_is_active (w))) |
1597 | if (expect_false (!ev_is_active (w))) |
1601 | return; |
1598 | return; |
1602 | |
1599 | |
… | |
… | |
1607 | #ifndef SA_RESTART |
1604 | #ifndef SA_RESTART |
1608 | # define SA_RESTART 0 |
1605 | # define SA_RESTART 0 |
1609 | #endif |
1606 | #endif |
1610 | |
1607 | |
1611 | void |
1608 | void |
1612 | ev_signal_start (EV_P_ struct ev_signal *w) |
1609 | ev_signal_start (EV_P_ ev_signal *w) |
1613 | { |
1610 | { |
1614 | #if EV_MULTIPLICITY |
1611 | #if EV_MULTIPLICITY |
1615 | assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1612 | assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1616 | #endif |
1613 | #endif |
1617 | if (expect_false (ev_is_active (w))) |
1614 | if (expect_false (ev_is_active (w))) |
… | |
… | |
1636 | #endif |
1633 | #endif |
1637 | } |
1634 | } |
1638 | } |
1635 | } |
1639 | |
1636 | |
1640 | void |
1637 | void |
1641 | ev_signal_stop (EV_P_ struct ev_signal *w) |
1638 | ev_signal_stop (EV_P_ ev_signal *w) |
1642 | { |
1639 | { |
1643 | ev_clear_pending (EV_A_ (W)w); |
1640 | ev_clear_pending (EV_A_ (W)w); |
1644 | if (expect_false (!ev_is_active (w))) |
1641 | if (expect_false (!ev_is_active (w))) |
1645 | return; |
1642 | return; |
1646 | |
1643 | |
… | |
… | |
1650 | if (!signals [w->signum - 1].head) |
1647 | if (!signals [w->signum - 1].head) |
1651 | signal (w->signum, SIG_DFL); |
1648 | signal (w->signum, SIG_DFL); |
1652 | } |
1649 | } |
1653 | |
1650 | |
1654 | void |
1651 | void |
1655 | ev_child_start (EV_P_ struct ev_child *w) |
1652 | ev_child_start (EV_P_ ev_child *w) |
1656 | { |
1653 | { |
1657 | #if EV_MULTIPLICITY |
1654 | #if EV_MULTIPLICITY |
1658 | assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1655 | assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1659 | #endif |
1656 | #endif |
1660 | if (expect_false (ev_is_active (w))) |
1657 | if (expect_false (ev_is_active (w))) |
… | |
… | |
1663 | ev_start (EV_A_ (W)w, 1); |
1660 | ev_start (EV_A_ (W)w, 1); |
1664 | wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1661 | wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1665 | } |
1662 | } |
1666 | |
1663 | |
1667 | void |
1664 | void |
1668 | ev_child_stop (EV_P_ struct ev_child *w) |
1665 | ev_child_stop (EV_P_ ev_child *w) |
1669 | { |
1666 | { |
1670 | ev_clear_pending (EV_A_ (W)w); |
1667 | ev_clear_pending (EV_A_ (W)w); |
1671 | if (expect_false (!ev_is_active (w))) |
1668 | if (expect_false (!ev_is_active (w))) |
1672 | return; |
1669 | return; |
1673 | |
1670 | |
1674 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1671 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1675 | ev_stop (EV_A_ (W)w); |
1672 | ev_stop (EV_A_ (W)w); |
1676 | } |
1673 | } |
1677 | |
1674 | |
1678 | #if EV_MULTIPLICITY |
1675 | #if EV_MULTIPLICITY |
1679 | static void |
1676 | void |
1680 | embed_cb (EV_P_ struct ev_io *io, int revents) |
1677 | ev_embed_loop (EV_P_ ev_embed *w) |
1681 | { |
1678 | { |
1682 | struct ev_embed *w = (struct ev_embed *)(((char *)io) - offsetof (struct ev_embed, io)); |
|
|
1683 | |
|
|
1684 | ev_feed_event (EV_A_ (W)w, EV_EMBED); |
|
|
1685 | ev_loop (w->loop, EVLOOP_NONBLOCK); |
1679 | ev_loop (w->loop, EVLOOP_NONBLOCK); |
1686 | } |
1680 | } |
1687 | |
1681 | |
|
|
1682 | static void |
|
|
1683 | embed_cb (EV_P_ ev_io *io, int revents) |
|
|
1684 | { |
|
|
1685 | ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); |
|
|
1686 | |
|
|
1687 | if (ev_cb (w)) |
|
|
1688 | ev_feed_event (EV_A_ (W)w, EV_EMBED); |
|
|
1689 | else |
|
|
1690 | ev_embed_loop (loop, w); |
|
|
1691 | } |
|
|
1692 | |
1688 | void |
1693 | void |
1689 | ev_embed_start (EV_P_ struct ev_embed *w) |
1694 | ev_embed_start (EV_P_ ev_embed *w) |
1690 | { |
1695 | { |
1691 | if (expect_false (ev_is_active (w))) |
1696 | if (expect_false (ev_is_active (w))) |
1692 | return; |
1697 | return; |
1693 | |
1698 | |
1694 | { |
1699 | { |
1695 | struct ev_loop *loop = w->loop; |
1700 | struct ev_loop *loop = w->loop; |
1696 | assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
1701 | assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
1697 | ev_io_init (&w->io, embed_cb, backend_fd, EV_READ); |
1702 | ev_io_init (&w->io, embed_cb, backend_fd, EV_READ); |
1698 | } |
1703 | } |
1699 | |
1704 | |
|
|
1705 | ev_set_priority (&w->io, ev_priority (w)); |
1700 | ev_io_start (EV_A_ &w->io); |
1706 | ev_io_start (EV_A_ &w->io); |
1701 | ev_start (EV_A_ (W)w, 1); |
1707 | ev_start (EV_A_ (W)w, 1); |
1702 | } |
1708 | } |
1703 | |
1709 | |
1704 | void |
1710 | void |
1705 | ev_embed_stop (EV_P_ struct ev_embed *w) |
1711 | ev_embed_stop (EV_P_ ev_embed *w) |
1706 | { |
1712 | { |
1707 | ev_clear_pending (EV_A_ (W)w); |
1713 | ev_clear_pending (EV_A_ (W)w); |
1708 | if (expect_false (!ev_is_active (w))) |
1714 | if (expect_false (!ev_is_active (w))) |
1709 | return; |
1715 | return; |
1710 | |
1716 | |
… | |
… | |
1715 | |
1721 | |
1716 | /*****************************************************************************/ |
1722 | /*****************************************************************************/ |
1717 | |
1723 | |
1718 | struct ev_once |
1724 | struct ev_once |
1719 | { |
1725 | { |
1720 | struct ev_io io; |
1726 | ev_io io; |
1721 | struct ev_timer to; |
1727 | ev_timer to; |
1722 | void (*cb)(int revents, void *arg); |
1728 | void (*cb)(int revents, void *arg); |
1723 | void *arg; |
1729 | void *arg; |
1724 | }; |
1730 | }; |
1725 | |
1731 | |
1726 | static void |
1732 | static void |
… | |
… | |
1735 | |
1741 | |
1736 | cb (revents, arg); |
1742 | cb (revents, arg); |
1737 | } |
1743 | } |
1738 | |
1744 | |
1739 | static void |
1745 | static void |
1740 | once_cb_io (EV_P_ struct ev_io *w, int revents) |
1746 | once_cb_io (EV_P_ ev_io *w, int revents) |
1741 | { |
1747 | { |
1742 | once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)), revents); |
1748 | once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)), revents); |
1743 | } |
1749 | } |
1744 | |
1750 | |
1745 | static void |
1751 | static void |
1746 | once_cb_to (EV_P_ struct ev_timer *w, int revents) |
1752 | once_cb_to (EV_P_ ev_timer *w, int revents) |
1747 | { |
1753 | { |
1748 | once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)), revents); |
1754 | once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)), revents); |
1749 | } |
1755 | } |
1750 | |
1756 | |
1751 | void |
1757 | void |