… | |
… | |
59 | |
59 | |
60 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE) |
60 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE) |
61 | # define EV_USE_KQUEUE 1 |
61 | # define EV_USE_KQUEUE 1 |
62 | # endif |
62 | # endif |
63 | |
63 | |
|
|
64 | # if HAVE_PORT_H && HAVE_PORT_CREATE && !defined (EV_USE_PORT) |
|
|
65 | # define EV_USE_PORT 1 |
|
|
66 | # endif |
|
|
67 | |
64 | #endif |
68 | #endif |
65 | |
69 | |
66 | #include <math.h> |
70 | #include <math.h> |
67 | #include <stdlib.h> |
71 | #include <stdlib.h> |
68 | #include <fcntl.h> |
72 | #include <fcntl.h> |
… | |
… | |
90 | #endif |
94 | #endif |
91 | |
95 | |
92 | /**/ |
96 | /**/ |
93 | |
97 | |
94 | #ifndef EV_USE_MONOTONIC |
98 | #ifndef EV_USE_MONOTONIC |
95 | # define EV_USE_MONOTONIC 1 |
99 | # define EV_USE_MONOTONIC 0 |
|
|
100 | #endif |
|
|
101 | |
|
|
102 | #ifndef EV_USE_REALTIME |
|
|
103 | # define EV_USE_REALTIME 0 |
96 | #endif |
104 | #endif |
97 | |
105 | |
98 | #ifndef EV_USE_SELECT |
106 | #ifndef EV_USE_SELECT |
99 | # define EV_USE_SELECT 1 |
107 | # define EV_USE_SELECT 1 |
100 | # define EV_SELECT_USE_FD_SET 1 |
|
|
101 | #endif |
108 | #endif |
102 | |
109 | |
103 | #ifndef EV_USE_POLL |
110 | #ifndef EV_USE_POLL |
104 | # ifdef _WIN32 |
111 | # ifdef _WIN32 |
105 | # define EV_USE_POLL 0 |
112 | # define EV_USE_POLL 0 |
… | |
… | |
114 | |
121 | |
115 | #ifndef EV_USE_KQUEUE |
122 | #ifndef EV_USE_KQUEUE |
116 | # define EV_USE_KQUEUE 0 |
123 | # define EV_USE_KQUEUE 0 |
117 | #endif |
124 | #endif |
118 | |
125 | |
119 | #ifndef EV_USE_REALTIME |
126 | #ifndef EV_USE_PORT |
120 | # define EV_USE_REALTIME 1 |
127 | # define EV_USE_PORT 0 |
121 | #endif |
128 | #endif |
122 | |
129 | |
123 | /**/ |
130 | /**/ |
124 | |
131 | |
125 | /* darwin simply cannot be helped */ |
132 | /* darwin simply cannot be helped */ |
… | |
… | |
143 | #endif |
150 | #endif |
144 | |
151 | |
145 | /**/ |
152 | /**/ |
146 | |
153 | |
147 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
154 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
148 | #define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */ |
155 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
149 | #define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ |
156 | #define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ |
150 | /*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */ |
157 | /*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */ |
151 | |
158 | |
152 | #ifdef EV_H |
159 | #ifdef EV_H |
153 | # include EV_H |
160 | # include EV_H |
154 | #else |
161 | #else |
155 | # include "ev.h" |
162 | # include "ev.h" |
… | |
… | |
258 | #include "ev_vars.h" |
265 | #include "ev_vars.h" |
259 | #undef VAR |
266 | #undef VAR |
260 | }; |
267 | }; |
261 | #include "ev_wrap.h" |
268 | #include "ev_wrap.h" |
262 | |
269 | |
263 | struct ev_loop default_loop_struct; |
270 | static struct ev_loop default_loop_struct; |
264 | static struct ev_loop *default_loop; |
271 | struct ev_loop *ev_default_loop_ptr; |
265 | |
272 | |
266 | #else |
273 | #else |
267 | |
274 | |
268 | ev_tstamp ev_rt_now; |
275 | ev_tstamp ev_rt_now; |
269 | #define VAR(name,decl) static decl; |
276 | #define VAR(name,decl) static decl; |
270 | #include "ev_vars.h" |
277 | #include "ev_vars.h" |
271 | #undef VAR |
278 | #undef VAR |
272 | |
279 | |
273 | static int default_loop; |
280 | static int ev_default_loop_ptr; |
274 | |
281 | |
275 | #endif |
282 | #endif |
276 | |
283 | |
277 | /*****************************************************************************/ |
284 | /*****************************************************************************/ |
278 | |
285 | |
… | |
… | |
614 | ev_feed_signal_event (EV_P_ int signum) |
621 | ev_feed_signal_event (EV_P_ int signum) |
615 | { |
622 | { |
616 | WL w; |
623 | WL w; |
617 | |
624 | |
618 | #if EV_MULTIPLICITY |
625 | #if EV_MULTIPLICITY |
619 | assert (("feeding signal events is only supported in the default loop", loop == default_loop)); |
626 | assert (("feeding signal events is only supported in the default loop", loop == ev_default_loop_ptr)); |
620 | #endif |
627 | #endif |
621 | |
628 | |
622 | --signum; |
629 | --signum; |
623 | |
630 | |
624 | if (signum < 0 || signum >= signalmax) |
631 | if (signum < 0 || signum >= signalmax) |
… | |
… | |
710 | |
717 | |
711 | #endif |
718 | #endif |
712 | |
719 | |
713 | /*****************************************************************************/ |
720 | /*****************************************************************************/ |
714 | |
721 | |
|
|
722 | #if EV_USE_PORT |
|
|
723 | # include "ev_port.c" |
|
|
724 | #endif |
715 | #if EV_USE_KQUEUE |
725 | #if EV_USE_KQUEUE |
716 | # include "ev_kqueue.c" |
726 | # include "ev_kqueue.c" |
717 | #endif |
727 | #endif |
718 | #if EV_USE_EPOLL |
728 | #if EV_USE_EPOLL |
719 | # include "ev_epoll.c" |
729 | # include "ev_epoll.c" |
… | |
… | |
778 | |
788 | |
779 | if (!(flags & 0x0000ffff)) |
789 | if (!(flags & 0x0000ffff)) |
780 | flags |= 0x0000ffff; |
790 | flags |= 0x0000ffff; |
781 | |
791 | |
782 | method = 0; |
792 | method = 0; |
|
|
793 | #if EV_USE_PORT |
|
|
794 | if (!method && (flags & EVMETHOD_PORT )) method = port_init (EV_A_ flags); |
|
|
795 | #endif |
783 | #if EV_USE_KQUEUE |
796 | #if EV_USE_KQUEUE |
784 | if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags); |
797 | if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags); |
785 | #endif |
798 | #endif |
786 | #if EV_USE_EPOLL |
799 | #if EV_USE_EPOLL |
787 | if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags); |
800 | if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags); |
… | |
… | |
801 | void |
814 | void |
802 | loop_destroy (EV_P) |
815 | loop_destroy (EV_P) |
803 | { |
816 | { |
804 | int i; |
817 | int i; |
805 | |
818 | |
|
|
819 | #if EV_USE_PORT |
|
|
820 | if (method == EVMETHOD_PORT ) port_destroy (EV_A); |
|
|
821 | #endif |
806 | #if EV_USE_KQUEUE |
822 | #if EV_USE_KQUEUE |
807 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
823 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
808 | #endif |
824 | #endif |
809 | #if EV_USE_EPOLL |
825 | #if EV_USE_EPOLL |
810 | if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); |
826 | if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); |
… | |
… | |
833 | } |
849 | } |
834 | |
850 | |
835 | static void |
851 | static void |
836 | loop_fork (EV_P) |
852 | loop_fork (EV_P) |
837 | { |
853 | { |
|
|
854 | #if EV_USE_PORT |
|
|
855 | if (method == EVMETHOD_PORT ) port_fork (EV_A); |
|
|
856 | #endif |
|
|
857 | #if EV_USE_KQUEUE |
|
|
858 | if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); |
|
|
859 | #endif |
838 | #if EV_USE_EPOLL |
860 | #if EV_USE_EPOLL |
839 | if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); |
861 | if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); |
840 | #endif |
|
|
841 | #if EV_USE_KQUEUE |
|
|
842 | if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); |
|
|
843 | #endif |
862 | #endif |
844 | |
863 | |
845 | if (ev_is_active (&sigev)) |
864 | if (ev_is_active (&sigev)) |
846 | { |
865 | { |
847 | /* default loop */ |
866 | /* default loop */ |
… | |
… | |
891 | |
910 | |
892 | #endif |
911 | #endif |
893 | |
912 | |
894 | #if EV_MULTIPLICITY |
913 | #if EV_MULTIPLICITY |
895 | struct ev_loop * |
914 | struct ev_loop * |
|
|
915 | ev_default_loop_ (unsigned int flags) |
896 | #else |
916 | #else |
897 | int |
917 | int |
898 | #endif |
|
|
899 | ev_default_loop (unsigned int flags) |
918 | ev_default_loop (unsigned int flags) |
|
|
919 | #endif |
900 | { |
920 | { |
901 | if (sigpipe [0] == sigpipe [1]) |
921 | if (sigpipe [0] == sigpipe [1]) |
902 | if (pipe (sigpipe)) |
922 | if (pipe (sigpipe)) |
903 | return 0; |
923 | return 0; |
904 | |
924 | |
905 | if (!default_loop) |
925 | if (!ev_default_loop_ptr) |
906 | { |
926 | { |
907 | #if EV_MULTIPLICITY |
927 | #if EV_MULTIPLICITY |
908 | struct ev_loop *loop = default_loop = &default_loop_struct; |
928 | struct ev_loop *loop = ev_default_loop_ptr = &default_loop_struct; |
909 | #else |
929 | #else |
910 | default_loop = 1; |
930 | ev_default_loop_ptr = 1; |
911 | #endif |
931 | #endif |
912 | |
932 | |
913 | loop_init (EV_A_ flags); |
933 | loop_init (EV_A_ flags); |
914 | |
934 | |
915 | if (ev_method (EV_A)) |
935 | if (ev_method (EV_A)) |
… | |
… | |
922 | ev_signal_start (EV_A_ &childev); |
942 | ev_signal_start (EV_A_ &childev); |
923 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
943 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
924 | #endif |
944 | #endif |
925 | } |
945 | } |
926 | else |
946 | else |
927 | default_loop = 0; |
947 | ev_default_loop_ptr = 0; |
928 | } |
948 | } |
929 | |
949 | |
930 | return default_loop; |
950 | return ev_default_loop_ptr; |
931 | } |
951 | } |
932 | |
952 | |
933 | void |
953 | void |
934 | ev_default_destroy (void) |
954 | ev_default_destroy (void) |
935 | { |
955 | { |
936 | #if EV_MULTIPLICITY |
956 | #if EV_MULTIPLICITY |
937 | struct ev_loop *loop = default_loop; |
957 | struct ev_loop *loop = ev_default_loop_ptr; |
938 | #endif |
958 | #endif |
939 | |
959 | |
940 | #ifndef _WIN32 |
960 | #ifndef _WIN32 |
941 | ev_ref (EV_A); /* child watcher */ |
961 | ev_ref (EV_A); /* child watcher */ |
942 | ev_signal_stop (EV_A_ &childev); |
962 | ev_signal_stop (EV_A_ &childev); |
… | |
… | |
953 | |
973 | |
954 | void |
974 | void |
955 | ev_default_fork (void) |
975 | ev_default_fork (void) |
956 | { |
976 | { |
957 | #if EV_MULTIPLICITY |
977 | #if EV_MULTIPLICITY |
958 | struct ev_loop *loop = default_loop; |
978 | struct ev_loop *loop = ev_default_loop_ptr; |
959 | #endif |
979 | #endif |
960 | |
980 | |
961 | if (method) |
981 | if (method) |
962 | postfork = 1; |
982 | postfork = 1; |
963 | } |
983 | } |
… | |
… | |
1516 | |
1536 | |
1517 | void |
1537 | void |
1518 | ev_signal_start (EV_P_ struct ev_signal *w) |
1538 | ev_signal_start (EV_P_ struct ev_signal *w) |
1519 | { |
1539 | { |
1520 | #if EV_MULTIPLICITY |
1540 | #if EV_MULTIPLICITY |
1521 | assert (("signal watchers are only supported in the default loop", loop == default_loop)); |
1541 | assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1522 | #endif |
1542 | #endif |
1523 | if (ev_is_active (w)) |
1543 | if (ev_is_active (w)) |
1524 | return; |
1544 | return; |
1525 | |
1545 | |
1526 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
1546 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
… | |
… | |
1559 | |
1579 | |
1560 | void |
1580 | void |
1561 | ev_child_start (EV_P_ struct ev_child *w) |
1581 | ev_child_start (EV_P_ struct ev_child *w) |
1562 | { |
1582 | { |
1563 | #if EV_MULTIPLICITY |
1583 | #if EV_MULTIPLICITY |
1564 | assert (("child watchers are only supported in the default loop", loop == default_loop)); |
1584 | assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1565 | #endif |
1585 | #endif |
1566 | if (ev_is_active (w)) |
1586 | if (ev_is_active (w)) |
1567 | return; |
1587 | return; |
1568 | |
1588 | |
1569 | ev_start (EV_A_ (W)w, 1); |
1589 | ev_start (EV_A_ (W)w, 1); |