… | |
… | |
77 | # ifndef EV_USE_REALTIME |
77 | # ifndef EV_USE_REALTIME |
78 | # define EV_USE_REALTIME 0 |
78 | # define EV_USE_REALTIME 0 |
79 | # endif |
79 | # endif |
80 | # endif |
80 | # endif |
81 | |
81 | |
|
|
82 | # if HAVE_NANOSLEEP |
82 | # ifndef EV_USE_NANOSLEEP |
83 | # ifndef EV_USE_NANOSLEEP |
83 | # if HAVE_NANOSLEEP |
|
|
84 | # define EV_USE_NANOSLEEP 1 |
84 | # define EV_USE_NANOSLEEP EV_FEATURE_OS |
|
|
85 | # endif |
85 | # else |
86 | # else |
|
|
87 | # undef EV_USE_NANOSLEEP |
86 | # define EV_USE_NANOSLEEP 0 |
88 | # define EV_USE_NANOSLEEP 0 |
|
|
89 | # endif |
|
|
90 | |
|
|
91 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
|
|
92 | # ifndef EV_USE_SELECT |
|
|
93 | # define EV_USE_SELECT EV_FEATURE_BACKENDS |
87 | # endif |
94 | # endif |
|
|
95 | # else |
|
|
96 | # undef EV_USE_SELECT |
|
|
97 | # define EV_USE_SELECT 0 |
88 | # endif |
98 | # endif |
89 | |
99 | |
|
|
100 | # if HAVE_POLL && HAVE_POLL_H |
90 | # ifndef EV_USE_SELECT |
101 | # ifndef EV_USE_POLL |
91 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
102 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
92 | # define EV_USE_SELECT 1 |
|
|
93 | # else |
|
|
94 | # define EV_USE_SELECT 0 |
|
|
95 | # endif |
103 | # endif |
96 | # endif |
|
|
97 | |
|
|
98 | # ifndef EV_USE_POLL |
|
|
99 | # if HAVE_POLL && HAVE_POLL_H |
|
|
100 | # define EV_USE_POLL 1 |
|
|
101 | # else |
104 | # else |
|
|
105 | # undef EV_USE_POLL |
102 | # define EV_USE_POLL 0 |
106 | # define EV_USE_POLL 0 |
103 | # endif |
|
|
104 | # endif |
107 | # endif |
105 | |
108 | |
106 | # ifndef EV_USE_EPOLL |
|
|
107 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
109 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
108 | # define EV_USE_EPOLL 1 |
110 | # ifndef EV_USE_EPOLL |
109 | # else |
111 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
110 | # define EV_USE_EPOLL 0 |
|
|
111 | # endif |
112 | # endif |
|
|
113 | # else |
|
|
114 | # undef EV_USE_EPOLL |
|
|
115 | # define EV_USE_EPOLL 0 |
112 | # endif |
116 | # endif |
113 | |
117 | |
114 | # ifndef EV_USE_KQUEUE |
|
|
115 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
118 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
116 | # define EV_USE_KQUEUE 1 |
119 | # ifndef EV_USE_KQUEUE |
117 | # else |
120 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
118 | # define EV_USE_KQUEUE 0 |
|
|
119 | # endif |
121 | # endif |
|
|
122 | # else |
|
|
123 | # undef EV_USE_KQUEUE |
|
|
124 | # define EV_USE_KQUEUE 0 |
120 | # endif |
125 | # endif |
121 | |
126 | |
122 | # ifndef EV_USE_PORT |
|
|
123 | # if HAVE_PORT_H && HAVE_PORT_CREATE |
127 | # if HAVE_PORT_H && HAVE_PORT_CREATE |
124 | # define EV_USE_PORT 1 |
128 | # ifndef EV_USE_PORT |
125 | # else |
129 | # define EV_USE_PORT EV_FEATURE_BACKENDS |
126 | # define EV_USE_PORT 0 |
|
|
127 | # endif |
130 | # endif |
|
|
131 | # else |
|
|
132 | # undef EV_USE_PORT |
|
|
133 | # define EV_USE_PORT 0 |
128 | # endif |
134 | # endif |
129 | |
135 | |
130 | # ifndef EV_USE_INOTIFY |
|
|
131 | # if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H |
136 | # if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H |
132 | # define EV_USE_INOTIFY 1 |
137 | # ifndef EV_USE_INOTIFY |
133 | # else |
|
|
134 | # define EV_USE_INOTIFY 0 |
138 | # define EV_USE_INOTIFY EV_FEATURE_OS |
135 | # endif |
139 | # endif |
|
|
140 | # else |
|
|
141 | # undef EV_USE_INOTIFY |
|
|
142 | # define EV_USE_INOTIFY 0 |
136 | # endif |
143 | # endif |
137 | |
144 | |
138 | # ifndef EV_USE_SIGNALFD |
|
|
139 | # if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H |
145 | # if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H |
140 | # define EV_USE_SIGNALFD 1 |
146 | # ifndef EV_USE_SIGNALFD |
141 | # else |
|
|
142 | # define EV_USE_SIGNALFD 0 |
147 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
143 | # endif |
148 | # endif |
|
|
149 | # else |
|
|
150 | # undef EV_USE_SIGNALFD |
|
|
151 | # define EV_USE_SIGNALFD 0 |
144 | # endif |
152 | # endif |
145 | |
153 | |
|
|
154 | # if HAVE_EVENTFD |
146 | # ifndef EV_USE_EVENTFD |
155 | # ifndef EV_USE_EVENTFD |
147 | # if HAVE_EVENTFD |
|
|
148 | # define EV_USE_EVENTFD 1 |
156 | # define EV_USE_EVENTFD EV_FEATURE_OS |
149 | # else |
|
|
150 | # define EV_USE_EVENTFD 0 |
|
|
151 | # endif |
157 | # endif |
|
|
158 | # else |
|
|
159 | # undef EV_USE_EVENTFD |
|
|
160 | # define EV_USE_EVENTFD 0 |
152 | # endif |
161 | # endif |
153 | |
162 | |
154 | #endif |
163 | #endif |
155 | |
164 | |
156 | #include <math.h> |
165 | #include <math.h> |
… | |
… | |
186 | # ifndef EV_SELECT_IS_WINSOCKET |
195 | # ifndef EV_SELECT_IS_WINSOCKET |
187 | # define EV_SELECT_IS_WINSOCKET 1 |
196 | # define EV_SELECT_IS_WINSOCKET 1 |
188 | # endif |
197 | # endif |
189 | # undef EV_AVOID_STDIO |
198 | # undef EV_AVOID_STDIO |
190 | #endif |
199 | #endif |
|
|
200 | |
|
|
201 | /* OS X, in its infinite idiocy, actually HARDCODES |
|
|
202 | * a limit of 1024 into their select. Where people have brains, |
|
|
203 | * OS X engineers apparently have a vacuum. Or maybe they were |
|
|
204 | * ordered to have a vacuum, or they do anything for money. |
|
|
205 | * This might help. Or not. |
|
|
206 | */ |
|
|
207 | #define _DARWIN_UNLIMITED_SELECT 1 |
191 | |
208 | |
192 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
209 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
193 | |
210 | |
194 | /* try to deduce the maximum number of signals on this platform */ |
211 | /* try to deduce the maximum number of signals on this platform */ |
195 | #if defined (EV_NSIG) |
212 | #if defined (EV_NSIG) |
… | |
… | |
435 | |
452 | |
436 | |
453 | |
437 | /**/ |
454 | /**/ |
438 | |
455 | |
439 | #if EV_VERIFY >= 3 |
456 | #if EV_VERIFY >= 3 |
440 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
457 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
441 | #else |
458 | #else |
442 | # define EV_FREQUENT_CHECK do { } while (0) |
459 | # define EV_FREQUENT_CHECK do { } while (0) |
443 | #endif |
460 | #endif |
444 | |
461 | |
445 | /* |
462 | /* |
… | |
… | |
494 | #define ev_active(w) ((W)(w))->active |
511 | #define ev_active(w) ((W)(w))->active |
495 | #define ev_at(w) ((WT)(w))->at |
512 | #define ev_at(w) ((WT)(w))->at |
496 | |
513 | |
497 | #if EV_USE_REALTIME |
514 | #if EV_USE_REALTIME |
498 | /* sig_atomic_t is used to avoid per-thread variables or locking but still */ |
515 | /* sig_atomic_t is used to avoid per-thread variables or locking but still */ |
499 | /* giving it a reasonably high chance of working on typical architetcures */ |
516 | /* giving it a reasonably high chance of working on typical architectures */ |
500 | static EV_ATOMIC_T have_realtime; /* did clock_gettime (CLOCK_REALTIME) work? */ |
517 | static EV_ATOMIC_T have_realtime; /* did clock_gettime (CLOCK_REALTIME) work? */ |
501 | #endif |
518 | #endif |
502 | |
519 | |
503 | #if EV_USE_MONOTONIC |
520 | #if EV_USE_MONOTONIC |
504 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
521 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
… | |
… | |
777 | /*****************************************************************************/ |
794 | /*****************************************************************************/ |
778 | |
795 | |
779 | #define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ |
796 | #define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ |
780 | |
797 | |
781 | /* find a suitable new size for the given array, */ |
798 | /* find a suitable new size for the given array, */ |
782 | /* hopefully by rounding to a ncie-to-malloc size */ |
799 | /* hopefully by rounding to a nice-to-malloc size */ |
783 | inline_size int |
800 | inline_size int |
784 | array_nextsize (int elem, int cur, int cnt) |
801 | array_nextsize (int elem, int cur, int cnt) |
785 | { |
802 | { |
786 | int ncur = cur + 1; |
803 | int ncur = cur + 1; |
787 | |
804 | |
… | |
… | |
1054 | } |
1071 | } |
1055 | |
1072 | |
1056 | /*****************************************************************************/ |
1073 | /*****************************************************************************/ |
1057 | |
1074 | |
1058 | /* |
1075 | /* |
1059 | * the heap functions want a real array index. array index 0 uis guaranteed to not |
1076 | * the heap functions want a real array index. array index 0 is guaranteed to not |
1060 | * be in-use at any time. the first heap entry is at array [HEAP0]. DHEAP gives |
1077 | * be in-use at any time. the first heap entry is at array [HEAP0]. DHEAP gives |
1061 | * the branching factor of the d-tree. |
1078 | * the branching factor of the d-tree. |
1062 | */ |
1079 | */ |
1063 | |
1080 | |
1064 | /* |
1081 | /* |
… | |
… | |
1507 | #ifdef __APPLE__ |
1524 | #ifdef __APPLE__ |
1508 | /* only select works correctly on that "unix-certified" platform */ |
1525 | /* only select works correctly on that "unix-certified" platform */ |
1509 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1526 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1510 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1527 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1511 | #endif |
1528 | #endif |
|
|
1529 | #ifdef __FreeBSD__ |
|
|
1530 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
|
|
1531 | #endif |
1512 | |
1532 | |
1513 | return flags; |
1533 | return flags; |
1514 | } |
1534 | } |
1515 | |
1535 | |
1516 | unsigned int |
1536 | unsigned int |
… | |
… | |
1531 | return backend; |
1551 | return backend; |
1532 | } |
1552 | } |
1533 | |
1553 | |
1534 | #if EV_FEATURE_API |
1554 | #if EV_FEATURE_API |
1535 | unsigned int |
1555 | unsigned int |
1536 | ev_loop_count (EV_P) |
1556 | ev_iteration (EV_P) |
1537 | { |
1557 | { |
1538 | return loop_count; |
1558 | return loop_count; |
1539 | } |
1559 | } |
1540 | |
1560 | |
1541 | unsigned int |
1561 | unsigned int |
1542 | ev_loop_depth (EV_P) |
1562 | ev_depth (EV_P) |
1543 | { |
1563 | { |
1544 | return loop_depth; |
1564 | return loop_depth; |
1545 | } |
1565 | } |
1546 | |
1566 | |
1547 | void |
1567 | void |
… | |
… | |
1868 | } |
1888 | } |
1869 | #endif |
1889 | #endif |
1870 | |
1890 | |
1871 | #if EV_FEATURE_API |
1891 | #if EV_FEATURE_API |
1872 | void |
1892 | void |
1873 | ev_loop_verify (EV_P) |
1893 | ev_verify (EV_P) |
1874 | { |
1894 | { |
1875 | #if EV_VERIFY |
1895 | #if EV_VERIFY |
1876 | int i; |
1896 | int i; |
1877 | WL w; |
1897 | WL w; |
1878 | |
1898 | |
… | |
… | |
2096 | EV_FREQUENT_CHECK; |
2116 | EV_FREQUENT_CHECK; |
2097 | feed_reverse (EV_A_ (W)w); |
2117 | feed_reverse (EV_A_ (W)w); |
2098 | } |
2118 | } |
2099 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2119 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2100 | |
2120 | |
2101 | feed_reverse_done (EV_A_ EV_TIMEOUT); |
2121 | feed_reverse_done (EV_A_ EV_TIMER); |
2102 | } |
2122 | } |
2103 | } |
2123 | } |
2104 | |
2124 | |
2105 | #if EV_PERIODIC_ENABLE |
2125 | #if EV_PERIODIC_ENABLE |
2106 | /* make periodics pending */ |
2126 | /* make periodics pending */ |
… | |
… | |
2159 | feed_reverse_done (EV_A_ EV_PERIODIC); |
2179 | feed_reverse_done (EV_A_ EV_PERIODIC); |
2160 | } |
2180 | } |
2161 | } |
2181 | } |
2162 | |
2182 | |
2163 | /* simply recalculate all periodics */ |
2183 | /* simply recalculate all periodics */ |
2164 | /* TODO: maybe ensure that at leats one event happens when jumping forward? */ |
2184 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
2165 | static void noinline |
2185 | static void noinline |
2166 | periodics_reschedule (EV_P) |
2186 | periodics_reschedule (EV_P) |
2167 | { |
2187 | { |
2168 | int i; |
2188 | int i; |
2169 | |
2189 | |
… | |
… | |
2280 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2300 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2281 | |
2301 | |
2282 | do |
2302 | do |
2283 | { |
2303 | { |
2284 | #if EV_VERIFY >= 2 |
2304 | #if EV_VERIFY >= 2 |
2285 | ev_loop_verify (EV_A); |
2305 | ev_verify (EV_A); |
2286 | #endif |
2306 | #endif |
2287 | |
2307 | |
2288 | #ifndef _WIN32 |
2308 | #ifndef _WIN32 |
2289 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2309 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2290 | if (expect_false (getpid () != curpid)) |
2310 | if (expect_false (getpid () != curpid)) |
… | |
… | |
3636 | { |
3656 | { |
3637 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3657 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3638 | |
3658 | |
3639 | if (expect_false (!once)) |
3659 | if (expect_false (!once)) |
3640 | { |
3660 | { |
3641 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
3661 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
3642 | return; |
3662 | return; |
3643 | } |
3663 | } |
3644 | |
3664 | |
3645 | once->cb = cb; |
3665 | once->cb = cb; |
3646 | once->arg = arg; |
3666 | once->arg = arg; |