… | |
… | |
156 | |
156 | |
157 | #ifndef EV_USE_PORT |
157 | #ifndef EV_USE_PORT |
158 | # define EV_USE_PORT 0 |
158 | # define EV_USE_PORT 0 |
159 | #endif |
159 | #endif |
160 | |
160 | |
|
|
161 | #ifndef EV_PID_HASHSIZE |
|
|
162 | # if EV_MINIMAL |
|
|
163 | # define EV_PID_HASHSIZE 1 |
|
|
164 | # else |
|
|
165 | # define EV_PID_HASHSIZE 16 |
|
|
166 | # endif |
|
|
167 | #endif |
|
|
168 | |
161 | /**/ |
169 | /**/ |
162 | |
170 | |
163 | #ifndef CLOCK_MONOTONIC |
171 | #ifndef CLOCK_MONOTONIC |
164 | # undef EV_USE_MONOTONIC |
172 | # undef EV_USE_MONOTONIC |
165 | # define EV_USE_MONOTONIC 0 |
173 | # define EV_USE_MONOTONIC 0 |
… | |
… | |
176 | |
184 | |
177 | /**/ |
185 | /**/ |
178 | |
186 | |
179 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
187 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
180 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
188 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
181 | #define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ |
|
|
182 | /*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */ |
189 | /*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */ |
183 | |
190 | |
184 | #ifdef EV_H |
191 | #ifdef EV_H |
185 | # include EV_H |
192 | # include EV_H |
186 | #else |
193 | #else |
… | |
… | |
709 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
716 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
710 | } |
717 | } |
711 | |
718 | |
712 | /*****************************************************************************/ |
719 | /*****************************************************************************/ |
713 | |
720 | |
714 | static ev_child *childs [PID_HASHSIZE]; |
721 | static ev_child *childs [EV_PID_HASHSIZE]; |
715 | |
722 | |
716 | #ifndef _WIN32 |
723 | #ifndef _WIN32 |
717 | |
724 | |
718 | static ev_signal childev; |
725 | static ev_signal childev; |
719 | |
726 | |
720 | void inline_speed |
727 | void inline_speed |
721 | child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) |
728 | child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) |
722 | { |
729 | { |
723 | ev_child *w; |
730 | ev_child *w; |
724 | |
731 | |
725 | for (w = (ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
732 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
726 | if (w->pid == pid || !w->pid) |
733 | if (w->pid == pid || !w->pid) |
727 | { |
734 | { |
728 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
735 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
729 | w->rpid = pid; |
736 | w->rpid = pid; |
730 | w->rstatus = status; |
737 | w->rstatus = status; |
… | |
… | |
751 | /* make sure we are called again until all childs have been reaped */ |
758 | /* make sure we are called again until all childs have been reaped */ |
752 | /* we need to do it this way so that the callback gets called before we continue */ |
759 | /* we need to do it this way so that the callback gets called before we continue */ |
753 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
760 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
754 | |
761 | |
755 | child_reap (EV_A_ sw, pid, pid, status); |
762 | child_reap (EV_A_ sw, pid, pid, status); |
|
|
763 | if (EV_PID_HASHSIZE > 1) |
756 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
764 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
757 | } |
765 | } |
758 | |
766 | |
759 | #endif |
767 | #endif |
760 | |
768 | |
761 | /*****************************************************************************/ |
769 | /*****************************************************************************/ |
… | |
… | |
1625 | #endif |
1633 | #endif |
1626 | if (expect_false (ev_is_active (w))) |
1634 | if (expect_false (ev_is_active (w))) |
1627 | return; |
1635 | return; |
1628 | |
1636 | |
1629 | ev_start (EV_A_ (W)w, 1); |
1637 | ev_start (EV_A_ (W)w, 1); |
1630 | wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1638 | wlist_add ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1631 | } |
1639 | } |
1632 | |
1640 | |
1633 | void |
1641 | void |
1634 | ev_child_stop (EV_P_ ev_child *w) |
1642 | ev_child_stop (EV_P_ ev_child *w) |
1635 | { |
1643 | { |
1636 | ev_clear_pending (EV_A_ (W)w); |
1644 | ev_clear_pending (EV_A_ (W)w); |
1637 | if (expect_false (!ev_is_active (w))) |
1645 | if (expect_false (!ev_is_active (w))) |
1638 | return; |
1646 | return; |
1639 | |
1647 | |
1640 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1648 | wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1641 | ev_stop (EV_A_ (W)w); |
1649 | ev_stop (EV_A_ (W)w); |
1642 | } |
1650 | } |
1643 | |
1651 | |
1644 | #if EV_STAT_ENABLE |
1652 | #if EV_STAT_ENABLE |
1645 | |
1653 | |