1 | /* |
1 | /* |
2 | * libev event processing core, watcher management |
2 | * libev event processing core, watcher management |
3 | * |
3 | * |
4 | * Copyright (c) 2007,2008,2009 Marc Alexander Lehmann <libev@schmorp.de> |
4 | * Copyright (c) 2007,2008,2009,2010 Marc Alexander Lehmann <libev@schmorp.de> |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
8 | * tion, are permitted provided that the following conditions are met: |
8 | * tion, are permitted provided that the following conditions are met: |
9 | * |
9 | * |
… | |
… | |
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 |
88 | # endif |
|
|
89 | |
|
|
90 | # ifndef EV_USE_SELECT |
|
|
91 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
|
|
92 | # define EV_USE_SELECT 1 |
|
|
93 | # else |
95 | # else |
|
|
96 | # undef EV_USE_SELECT |
94 | # define EV_USE_SELECT 0 |
97 | # define EV_USE_SELECT 0 |
|
|
98 | # endif |
|
|
99 | |
|
|
100 | # if HAVE_POLL && HAVE_POLL_H |
|
|
101 | # ifndef EV_USE_POLL |
|
|
102 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
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 |
|
|
107 | # endif |
|
|
108 | |
|
|
109 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
|
|
110 | # ifndef EV_USE_EPOLL |
|
|
111 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
103 | # endif |
112 | # endif |
|
|
113 | # else |
|
|
114 | # undef EV_USE_EPOLL |
|
|
115 | # define EV_USE_EPOLL 0 |
104 | # endif |
116 | # endif |
105 | |
117 | |
|
|
118 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
106 | # ifndef EV_USE_EPOLL |
119 | # ifndef EV_USE_KQUEUE |
107 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
120 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
108 | # define EV_USE_EPOLL 1 |
|
|
109 | # else |
|
|
110 | # define EV_USE_EPOLL 0 |
|
|
111 | # endif |
121 | # endif |
|
|
122 | # else |
|
|
123 | # undef EV_USE_KQUEUE |
|
|
124 | # define EV_USE_KQUEUE 0 |
112 | # endif |
125 | # endif |
113 | |
126 | |
114 | # ifndef EV_USE_KQUEUE |
127 | # if HAVE_PORT_H && HAVE_PORT_CREATE |
115 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H |
128 | # ifndef EV_USE_PORT |
116 | # define EV_USE_KQUEUE 1 |
129 | # define EV_USE_PORT EV_FEATURE_BACKENDS |
117 | # else |
|
|
118 | # define EV_USE_KQUEUE 0 |
|
|
119 | # endif |
130 | # endif |
120 | # endif |
|
|
121 | |
|
|
122 | # ifndef EV_USE_PORT |
|
|
123 | # if HAVE_PORT_H && HAVE_PORT_CREATE |
|
|
124 | # define EV_USE_PORT 1 |
|
|
125 | # else |
131 | # else |
|
|
132 | # undef EV_USE_PORT |
126 | # define EV_USE_PORT 0 |
133 | # define EV_USE_PORT 0 |
|
|
134 | # endif |
|
|
135 | |
|
|
136 | # if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H |
|
|
137 | # ifndef EV_USE_INOTIFY |
|
|
138 | # define EV_USE_INOTIFY EV_FEATURE_OS |
127 | # endif |
139 | # endif |
128 | # endif |
|
|
129 | |
|
|
130 | # ifndef EV_USE_INOTIFY |
|
|
131 | # if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H |
|
|
132 | # define EV_USE_INOTIFY 1 |
|
|
133 | # else |
140 | # else |
|
|
141 | # undef EV_USE_INOTIFY |
134 | # define EV_USE_INOTIFY 0 |
142 | # define EV_USE_INOTIFY 0 |
|
|
143 | # endif |
|
|
144 | |
|
|
145 | # if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H |
|
|
146 | # ifndef EV_USE_SIGNALFD |
|
|
147 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
135 | # endif |
148 | # endif |
136 | # endif |
|
|
137 | |
|
|
138 | # ifndef EV_USE_SIGNALFD |
|
|
139 | # if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H |
|
|
140 | # define EV_USE_SIGNALFD 1 |
|
|
141 | # else |
149 | # else |
|
|
150 | # undef EV_USE_SIGNALFD |
142 | # define EV_USE_SIGNALFD 0 |
151 | # define EV_USE_SIGNALFD 0 |
|
|
152 | # endif |
|
|
153 | |
|
|
154 | # if HAVE_EVENTFD |
|
|
155 | # ifndef EV_USE_EVENTFD |
|
|
156 | # define EV_USE_EVENTFD EV_FEATURE_OS |
143 | # endif |
157 | # endif |
144 | # endif |
|
|
145 | |
|
|
146 | # ifndef EV_USE_EVENTFD |
|
|
147 | # if HAVE_EVENTFD |
|
|
148 | # define EV_USE_EVENTFD 1 |
|
|
149 | # else |
158 | # else |
|
|
159 | # undef EV_USE_EVENTFD |
150 | # define EV_USE_EVENTFD 0 |
160 | # define EV_USE_EVENTFD 0 |
151 | # endif |
|
|
152 | # endif |
161 | # endif |
153 | |
162 | |
154 | #endif |
163 | #endif |
155 | |
164 | |
156 | #include <math.h> |
165 | #include <math.h> |
157 | #include <stdlib.h> |
166 | #include <stdlib.h> |
|
|
167 | #include <string.h> |
158 | #include <fcntl.h> |
168 | #include <fcntl.h> |
159 | #include <stddef.h> |
169 | #include <stddef.h> |
160 | |
170 | |
161 | #include <stdio.h> |
171 | #include <stdio.h> |
162 | |
172 | |
163 | #include <assert.h> |
173 | #include <assert.h> |
164 | #include <errno.h> |
174 | #include <errno.h> |
165 | #include <sys/types.h> |
175 | #include <sys/types.h> |
166 | #include <time.h> |
176 | #include <time.h> |
|
|
177 | #include <limits.h> |
167 | |
178 | |
168 | #include <signal.h> |
179 | #include <signal.h> |
169 | |
180 | |
170 | #ifdef EV_H |
181 | #ifdef EV_H |
171 | # include EV_H |
182 | # include EV_H |
… | |
… | |
182 | # define WIN32_LEAN_AND_MEAN |
193 | # define WIN32_LEAN_AND_MEAN |
183 | # include <windows.h> |
194 | # include <windows.h> |
184 | # ifndef EV_SELECT_IS_WINSOCKET |
195 | # ifndef EV_SELECT_IS_WINSOCKET |
185 | # define EV_SELECT_IS_WINSOCKET 1 |
196 | # define EV_SELECT_IS_WINSOCKET 1 |
186 | # endif |
197 | # endif |
|
|
198 | # undef EV_AVOID_STDIO |
187 | #endif |
199 | #endif |
188 | |
200 | |
189 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
201 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
190 | |
202 | |
191 | /* try to deduce the maximum number of signals on this platform */ |
203 | /* try to deduce the maximum number of signals on this platform */ |
… | |
… | |
204 | #elif defined (MAXSIG) |
216 | #elif defined (MAXSIG) |
205 | # define EV_NSIG (MAXSIG+1) |
217 | # define EV_NSIG (MAXSIG+1) |
206 | #elif defined (MAX_SIG) |
218 | #elif defined (MAX_SIG) |
207 | # define EV_NSIG (MAX_SIG+1) |
219 | # define EV_NSIG (MAX_SIG+1) |
208 | #elif defined (SIGARRAYSIZE) |
220 | #elif defined (SIGARRAYSIZE) |
209 | # define EV_NSIG SIGARRAYSIZE /* Assume ary[SIGARRAYSIZE] */ |
221 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
210 | #elif defined (_sys_nsig) |
222 | #elif defined (_sys_nsig) |
211 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
223 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
212 | #else |
224 | #else |
213 | # error "unable to find value for NSIG, please report" |
225 | # error "unable to find value for NSIG, please report" |
214 | /* to make it compile regardless, just remove the above line */ |
226 | /* to make it compile regardless, just remove the above line, */ |
|
|
227 | /* but consider reporting it, too! :) */ |
215 | # define EV_NSIG 64 |
228 | # define EV_NSIG 65 |
216 | #endif |
229 | #endif |
217 | |
230 | |
218 | /* Default to some arbitrary number that's big enough to get most |
|
|
219 | of the common signals. |
|
|
220 | */ |
|
|
221 | #ifndef NSIG |
|
|
222 | # define NSIG 50 |
|
|
223 | #endif |
|
|
224 | /* <-- NSIG logic from Configure */ |
|
|
225 | #ifndef EV_USE_CLOCK_SYSCALL |
231 | #ifndef EV_USE_CLOCK_SYSCALL |
226 | # if __linux && __GLIBC__ >= 2 |
232 | # if __linux && __GLIBC__ >= 2 |
227 | # define EV_USE_CLOCK_SYSCALL 1 |
233 | # define EV_USE_CLOCK_SYSCALL EV_FEATURE_OS |
228 | # else |
234 | # else |
229 | # define EV_USE_CLOCK_SYSCALL 0 |
235 | # define EV_USE_CLOCK_SYSCALL 0 |
230 | # endif |
236 | # endif |
231 | #endif |
237 | #endif |
232 | |
238 | |
233 | #ifndef EV_USE_MONOTONIC |
239 | #ifndef EV_USE_MONOTONIC |
234 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
240 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
235 | # define EV_USE_MONOTONIC 1 |
241 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
236 | # else |
242 | # else |
237 | # define EV_USE_MONOTONIC 0 |
243 | # define EV_USE_MONOTONIC 0 |
238 | # endif |
244 | # endif |
239 | #endif |
245 | #endif |
240 | |
246 | |
… | |
… | |
242 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
248 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
243 | #endif |
249 | #endif |
244 | |
250 | |
245 | #ifndef EV_USE_NANOSLEEP |
251 | #ifndef EV_USE_NANOSLEEP |
246 | # if _POSIX_C_SOURCE >= 199309L |
252 | # if _POSIX_C_SOURCE >= 199309L |
247 | # define EV_USE_NANOSLEEP 1 |
253 | # define EV_USE_NANOSLEEP EV_FEATURE_OS |
248 | # else |
254 | # else |
249 | # define EV_USE_NANOSLEEP 0 |
255 | # define EV_USE_NANOSLEEP 0 |
250 | # endif |
256 | # endif |
251 | #endif |
257 | #endif |
252 | |
258 | |
253 | #ifndef EV_USE_SELECT |
259 | #ifndef EV_USE_SELECT |
254 | # define EV_USE_SELECT 1 |
260 | # define EV_USE_SELECT EV_FEATURE_BACKENDS |
255 | #endif |
261 | #endif |
256 | |
262 | |
257 | #ifndef EV_USE_POLL |
263 | #ifndef EV_USE_POLL |
258 | # ifdef _WIN32 |
264 | # ifdef _WIN32 |
259 | # define EV_USE_POLL 0 |
265 | # define EV_USE_POLL 0 |
260 | # else |
266 | # else |
261 | # define EV_USE_POLL 1 |
267 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
262 | # endif |
268 | # endif |
263 | #endif |
269 | #endif |
264 | |
270 | |
265 | #ifndef EV_USE_EPOLL |
271 | #ifndef EV_USE_EPOLL |
266 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
272 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
267 | # define EV_USE_EPOLL 1 |
273 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
268 | # else |
274 | # else |
269 | # define EV_USE_EPOLL 0 |
275 | # define EV_USE_EPOLL 0 |
270 | # endif |
276 | # endif |
271 | #endif |
277 | #endif |
272 | |
278 | |
… | |
… | |
278 | # define EV_USE_PORT 0 |
284 | # define EV_USE_PORT 0 |
279 | #endif |
285 | #endif |
280 | |
286 | |
281 | #ifndef EV_USE_INOTIFY |
287 | #ifndef EV_USE_INOTIFY |
282 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
288 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
283 | # define EV_USE_INOTIFY 1 |
289 | # define EV_USE_INOTIFY EV_FEATURE_OS |
284 | # else |
290 | # else |
285 | # define EV_USE_INOTIFY 0 |
291 | # define EV_USE_INOTIFY 0 |
286 | # endif |
292 | # endif |
287 | #endif |
293 | #endif |
288 | |
294 | |
289 | #ifndef EV_PID_HASHSIZE |
295 | #ifndef EV_PID_HASHSIZE |
290 | # if EV_MINIMAL |
296 | # define EV_PID_HASHSIZE EV_FEATURE_DATA ? 16 : 1 |
291 | # define EV_PID_HASHSIZE 1 |
|
|
292 | # else |
|
|
293 | # define EV_PID_HASHSIZE 16 |
|
|
294 | # endif |
|
|
295 | #endif |
297 | #endif |
296 | |
298 | |
297 | #ifndef EV_INOTIFY_HASHSIZE |
299 | #ifndef EV_INOTIFY_HASHSIZE |
298 | # if EV_MINIMAL |
300 | # define EV_INOTIFY_HASHSIZE EV_FEATURE_DATA ? 16 : 1 |
299 | # define EV_INOTIFY_HASHSIZE 1 |
|
|
300 | # else |
|
|
301 | # define EV_INOTIFY_HASHSIZE 16 |
|
|
302 | # endif |
|
|
303 | #endif |
301 | #endif |
304 | |
302 | |
305 | #ifndef EV_USE_EVENTFD |
303 | #ifndef EV_USE_EVENTFD |
306 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
304 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
307 | # define EV_USE_EVENTFD 1 |
305 | # define EV_USE_EVENTFD EV_FEATURE_OS |
308 | # else |
306 | # else |
309 | # define EV_USE_EVENTFD 0 |
307 | # define EV_USE_EVENTFD 0 |
310 | # endif |
308 | # endif |
311 | #endif |
309 | #endif |
312 | |
310 | |
313 | #ifndef EV_USE_SIGNALFD |
311 | #ifndef EV_USE_SIGNALFD |
314 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9)) |
312 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
315 | # define EV_USE_SIGNALFD 1 |
313 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
316 | # else |
314 | # else |
317 | # define EV_USE_SIGNALFD 0 |
315 | # define EV_USE_SIGNALFD 0 |
318 | # endif |
316 | # endif |
319 | #endif |
317 | #endif |
320 | |
318 | |
… | |
… | |
323 | # define EV_USE_4HEAP 1 |
321 | # define EV_USE_4HEAP 1 |
324 | # define EV_HEAP_CACHE_AT 1 |
322 | # define EV_HEAP_CACHE_AT 1 |
325 | #endif |
323 | #endif |
326 | |
324 | |
327 | #ifndef EV_VERIFY |
325 | #ifndef EV_VERIFY |
328 | # define EV_VERIFY !EV_MINIMAL |
326 | # define EV_VERIFY (EV_FEATURE_API ? 1 : 0) |
329 | #endif |
327 | #endif |
330 | |
328 | |
331 | #ifndef EV_USE_4HEAP |
329 | #ifndef EV_USE_4HEAP |
332 | # define EV_USE_4HEAP !EV_MINIMAL |
330 | # define EV_USE_4HEAP EV_FEATURE_DATA |
333 | #endif |
331 | #endif |
334 | |
332 | |
335 | #ifndef EV_HEAP_CACHE_AT |
333 | #ifndef EV_HEAP_CACHE_AT |
336 | # define EV_HEAP_CACHE_AT !EV_MINIMAL |
334 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
337 | #endif |
335 | #endif |
338 | |
336 | |
339 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
337 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
340 | /* which makes programs even slower. might work on other unices, too. */ |
338 | /* which makes programs even slower. might work on other unices, too. */ |
341 | #if EV_USE_CLOCK_SYSCALL |
339 | #if EV_USE_CLOCK_SYSCALL |
… | |
… | |
350 | # endif |
348 | # endif |
351 | #endif |
349 | #endif |
352 | |
350 | |
353 | /* this block fixes any misconfiguration where we know we run into trouble otherwise */ |
351 | /* this block fixes any misconfiguration where we know we run into trouble otherwise */ |
354 | |
352 | |
|
|
353 | #ifdef _AIX |
|
|
354 | /* AIX has a completely broken poll.h header */ |
|
|
355 | # undef EV_USE_POLL |
|
|
356 | # define EV_USE_POLL 0 |
|
|
357 | #endif |
|
|
358 | |
355 | #ifndef CLOCK_MONOTONIC |
359 | #ifndef CLOCK_MONOTONIC |
356 | # undef EV_USE_MONOTONIC |
360 | # undef EV_USE_MONOTONIC |
357 | # define EV_USE_MONOTONIC 0 |
361 | # define EV_USE_MONOTONIC 0 |
358 | #endif |
362 | #endif |
359 | |
363 | |
… | |
… | |
393 | # include <stdint.h> |
397 | # include <stdint.h> |
394 | # ifndef EFD_NONBLOCK |
398 | # ifndef EFD_NONBLOCK |
395 | # define EFD_NONBLOCK O_NONBLOCK |
399 | # define EFD_NONBLOCK O_NONBLOCK |
396 | # endif |
400 | # endif |
397 | # ifndef EFD_CLOEXEC |
401 | # ifndef EFD_CLOEXEC |
|
|
402 | # ifdef O_CLOEXEC |
398 | # define EFD_CLOEXEC O_CLOEXEC |
403 | # define EFD_CLOEXEC O_CLOEXEC |
|
|
404 | # else |
|
|
405 | # define EFD_CLOEXEC 02000000 |
|
|
406 | # endif |
399 | # endif |
407 | # endif |
400 | # ifdef __cplusplus |
408 | # ifdef __cplusplus |
401 | extern "C" { |
409 | extern "C" { |
402 | # endif |
410 | # endif |
403 | int eventfd (unsigned int initval, int flags); |
411 | int (eventfd) (unsigned int initval, int flags); |
404 | # ifdef __cplusplus |
412 | # ifdef __cplusplus |
405 | } |
413 | } |
406 | # endif |
414 | # endif |
407 | #endif |
415 | #endif |
408 | |
416 | |
409 | #if EV_USE_SIGNALFD |
417 | #if EV_USE_SIGNALFD |
410 | # include <sys/signalfd.h> |
418 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
|
|
419 | # include <stdint.h> |
|
|
420 | # ifndef SFD_NONBLOCK |
|
|
421 | # define SFD_NONBLOCK O_NONBLOCK |
411 | #endif |
422 | # endif |
|
|
423 | # ifndef SFD_CLOEXEC |
|
|
424 | # ifdef O_CLOEXEC |
|
|
425 | # define SFD_CLOEXEC O_CLOEXEC |
|
|
426 | # else |
|
|
427 | # define SFD_CLOEXEC 02000000 |
|
|
428 | # endif |
|
|
429 | # endif |
|
|
430 | # ifdef __cplusplus |
|
|
431 | extern "C" { |
|
|
432 | # endif |
|
|
433 | int signalfd (int fd, const sigset_t *mask, int flags); |
|
|
434 | |
|
|
435 | struct signalfd_siginfo |
|
|
436 | { |
|
|
437 | uint32_t ssi_signo; |
|
|
438 | char pad[128 - sizeof (uint32_t)]; |
|
|
439 | }; |
|
|
440 | # ifdef __cplusplus |
|
|
441 | } |
|
|
442 | # endif |
|
|
443 | #endif |
|
|
444 | |
412 | |
445 | |
413 | /**/ |
446 | /**/ |
414 | |
447 | |
415 | #if EV_VERIFY >= 3 |
448 | #if EV_VERIFY >= 3 |
416 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
449 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
417 | #else |
450 | #else |
418 | # define EV_FREQUENT_CHECK do { } while (0) |
451 | # define EV_FREQUENT_CHECK do { } while (0) |
419 | #endif |
452 | #endif |
420 | |
453 | |
421 | /* |
454 | /* |
… | |
… | |
428 | */ |
461 | */ |
429 | #define TIME_EPSILON 0.0001220703125 /* 1/8192 */ |
462 | #define TIME_EPSILON 0.0001220703125 /* 1/8192 */ |
430 | |
463 | |
431 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
464 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
432 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
465 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
433 | /*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds, TODO */ |
|
|
434 | |
466 | |
435 | #if __GNUC__ >= 4 |
467 | #if __GNUC__ >= 4 |
436 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
468 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
437 | # define noinline __attribute__ ((noinline)) |
469 | # define noinline __attribute__ ((noinline)) |
438 | #else |
470 | #else |
… | |
… | |
445 | |
477 | |
446 | #define expect_false(expr) expect ((expr) != 0, 0) |
478 | #define expect_false(expr) expect ((expr) != 0, 0) |
447 | #define expect_true(expr) expect ((expr) != 0, 1) |
479 | #define expect_true(expr) expect ((expr) != 0, 1) |
448 | #define inline_size static inline |
480 | #define inline_size static inline |
449 | |
481 | |
450 | #if EV_MINIMAL |
482 | #if EV_FEATURE_CODE |
|
|
483 | # define inline_speed static inline |
|
|
484 | #else |
451 | # define inline_speed static noinline |
485 | # define inline_speed static noinline |
452 | #else |
|
|
453 | # define inline_speed static inline |
|
|
454 | #endif |
486 | #endif |
455 | |
487 | |
456 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
488 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
457 | |
489 | |
458 | #if EV_MINPRI == EV_MAXPRI |
490 | #if EV_MINPRI == EV_MAXPRI |
… | |
… | |
479 | |
511 | |
480 | #if EV_USE_MONOTONIC |
512 | #if EV_USE_MONOTONIC |
481 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
513 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
482 | #endif |
514 | #endif |
483 | |
515 | |
|
|
516 | #ifndef EV_FD_TO_WIN32_HANDLE |
|
|
517 | # define EV_FD_TO_WIN32_HANDLE(fd) _get_osfhandle (fd) |
|
|
518 | #endif |
|
|
519 | #ifndef EV_WIN32_HANDLE_TO_FD |
|
|
520 | # define EV_WIN32_HANDLE_TO_FD(handle) _open_osfhandle (handle, 0) |
|
|
521 | #endif |
|
|
522 | #ifndef EV_WIN32_CLOSE_FD |
|
|
523 | # define EV_WIN32_CLOSE_FD(fd) close (fd) |
|
|
524 | #endif |
|
|
525 | |
484 | #ifdef _WIN32 |
526 | #ifdef _WIN32 |
485 | # include "ev_win32.c" |
527 | # include "ev_win32.c" |
486 | #endif |
528 | #endif |
487 | |
529 | |
488 | /*****************************************************************************/ |
530 | /*****************************************************************************/ |
|
|
531 | |
|
|
532 | #if EV_AVOID_STDIO |
|
|
533 | static void noinline |
|
|
534 | ev_printerr (const char *msg) |
|
|
535 | { |
|
|
536 | write (STDERR_FILENO, msg, strlen (msg)); |
|
|
537 | } |
|
|
538 | #endif |
489 | |
539 | |
490 | static void (*syserr_cb)(const char *msg); |
540 | static void (*syserr_cb)(const char *msg); |
491 | |
541 | |
492 | void |
542 | void |
493 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
543 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
… | |
… | |
503 | |
553 | |
504 | if (syserr_cb) |
554 | if (syserr_cb) |
505 | syserr_cb (msg); |
555 | syserr_cb (msg); |
506 | else |
556 | else |
507 | { |
557 | { |
|
|
558 | #if EV_AVOID_STDIO |
|
|
559 | const char *err = strerror (errno); |
|
|
560 | |
|
|
561 | ev_printerr (msg); |
|
|
562 | ev_printerr (": "); |
|
|
563 | ev_printerr (err); |
|
|
564 | ev_printerr ("\n"); |
|
|
565 | #else |
508 | perror (msg); |
566 | perror (msg); |
|
|
567 | #endif |
509 | abort (); |
568 | abort (); |
510 | } |
569 | } |
511 | } |
570 | } |
512 | |
571 | |
513 | static void * |
572 | static void * |
514 | ev_realloc_emul (void *ptr, long size) |
573 | ev_realloc_emul (void *ptr, long size) |
515 | { |
574 | { |
|
|
575 | #if __GLIBC__ |
|
|
576 | return realloc (ptr, size); |
|
|
577 | #else |
516 | /* some systems, notably openbsd and darwin, fail to properly |
578 | /* some systems, notably openbsd and darwin, fail to properly |
517 | * implement realloc (x, 0) (as required by both ansi c-98 and |
579 | * implement realloc (x, 0) (as required by both ansi c-89 and |
518 | * the single unix specification, so work around them here. |
580 | * the single unix specification, so work around them here. |
519 | */ |
581 | */ |
520 | |
582 | |
521 | if (size) |
583 | if (size) |
522 | return realloc (ptr, size); |
584 | return realloc (ptr, size); |
523 | |
585 | |
524 | free (ptr); |
586 | free (ptr); |
525 | return 0; |
587 | return 0; |
|
|
588 | #endif |
526 | } |
589 | } |
527 | |
590 | |
528 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
591 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
529 | |
592 | |
530 | void |
593 | void |
… | |
… | |
538 | { |
601 | { |
539 | ptr = alloc (ptr, size); |
602 | ptr = alloc (ptr, size); |
540 | |
603 | |
541 | if (!ptr && size) |
604 | if (!ptr && size) |
542 | { |
605 | { |
|
|
606 | #if EV_AVOID_STDIO |
|
|
607 | ev_printerr ("libev: memory allocation failed, aborting.\n"); |
|
|
608 | #else |
543 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
609 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
|
|
610 | #endif |
544 | abort (); |
611 | abort (); |
545 | } |
612 | } |
546 | |
613 | |
547 | return ptr; |
614 | return ptr; |
548 | } |
615 | } |
… | |
… | |
630 | |
697 | |
631 | static int ev_default_loop_ptr; |
698 | static int ev_default_loop_ptr; |
632 | |
699 | |
633 | #endif |
700 | #endif |
634 | |
701 | |
635 | #if EV_MINIMAL < 2 |
702 | #if EV_FEATURE_API |
636 | # define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) |
703 | # define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) |
637 | # define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) |
704 | # define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) |
638 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
705 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
639 | #else |
706 | #else |
640 | # define EV_RELEASE_CB (void)0 |
707 | # define EV_RELEASE_CB (void)0 |
… | |
… | |
825 | } |
892 | } |
826 | |
893 | |
827 | /*****************************************************************************/ |
894 | /*****************************************************************************/ |
828 | |
895 | |
829 | inline_speed void |
896 | inline_speed void |
830 | fd_event_nc (EV_P_ int fd, int revents) |
897 | fd_event_nocheck (EV_P_ int fd, int revents) |
831 | { |
898 | { |
832 | ANFD *anfd = anfds + fd; |
899 | ANFD *anfd = anfds + fd; |
833 | ev_io *w; |
900 | ev_io *w; |
834 | |
901 | |
835 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
902 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
… | |
… | |
847 | fd_event (EV_P_ int fd, int revents) |
914 | fd_event (EV_P_ int fd, int revents) |
848 | { |
915 | { |
849 | ANFD *anfd = anfds + fd; |
916 | ANFD *anfd = anfds + fd; |
850 | |
917 | |
851 | if (expect_true (!anfd->reify)) |
918 | if (expect_true (!anfd->reify)) |
852 | fd_event_nc (EV_A_ fd, revents); |
919 | fd_event_nocheck (EV_A_ fd, revents); |
853 | } |
920 | } |
854 | |
921 | |
855 | void |
922 | void |
856 | ev_feed_fd_event (EV_P_ int fd, int revents) |
923 | ev_feed_fd_event (EV_P_ int fd, int revents) |
857 | { |
924 | { |
858 | if (fd >= 0 && fd < anfdmax) |
925 | if (fd >= 0 && fd < anfdmax) |
859 | fd_event_nc (EV_A_ fd, revents); |
926 | fd_event_nocheck (EV_A_ fd, revents); |
860 | } |
927 | } |
861 | |
928 | |
862 | /* make sure the external fd watch events are in-sync */ |
929 | /* make sure the external fd watch events are in-sync */ |
863 | /* with the kernel/libev internal state */ |
930 | /* with the kernel/libev internal state */ |
864 | inline_size void |
931 | inline_size void |
… | |
… | |
879 | |
946 | |
880 | #if EV_SELECT_IS_WINSOCKET |
947 | #if EV_SELECT_IS_WINSOCKET |
881 | if (events) |
948 | if (events) |
882 | { |
949 | { |
883 | unsigned long arg; |
950 | unsigned long arg; |
884 | #ifdef EV_FD_TO_WIN32_HANDLE |
|
|
885 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
951 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
886 | #else |
|
|
887 | anfd->handle = _get_osfhandle (fd); |
|
|
888 | #endif |
|
|
889 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
952 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
890 | } |
953 | } |
891 | #endif |
954 | #endif |
892 | |
955 | |
893 | { |
956 | { |
… | |
… | |
931 | ev_io_stop (EV_A_ w); |
994 | ev_io_stop (EV_A_ w); |
932 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
995 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
933 | } |
996 | } |
934 | } |
997 | } |
935 | |
998 | |
936 | /* check whether the given fd is atcually valid, for error recovery */ |
999 | /* check whether the given fd is actually valid, for error recovery */ |
937 | inline_size int |
1000 | inline_size int |
938 | fd_valid (int fd) |
1001 | fd_valid (int fd) |
939 | { |
1002 | { |
940 | #ifdef _WIN32 |
1003 | #ifdef _WIN32 |
941 | return _get_osfhandle (fd) != -1; |
1004 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
942 | #else |
1005 | #else |
943 | return fcntl (fd, F_GETFD) != -1; |
1006 | return fcntl (fd, F_GETFD) != -1; |
944 | #endif |
1007 | #endif |
945 | } |
1008 | } |
946 | |
1009 | |
… | |
… | |
964 | |
1027 | |
965 | for (fd = anfdmax; fd--; ) |
1028 | for (fd = anfdmax; fd--; ) |
966 | if (anfds [fd].events) |
1029 | if (anfds [fd].events) |
967 | { |
1030 | { |
968 | fd_kill (EV_A_ fd); |
1031 | fd_kill (EV_A_ fd); |
969 | return; |
1032 | break; |
970 | } |
1033 | } |
971 | } |
1034 | } |
972 | |
1035 | |
973 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
1036 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
974 | static void noinline |
1037 | static void noinline |
… | |
… | |
981 | { |
1044 | { |
982 | anfds [fd].events = 0; |
1045 | anfds [fd].events = 0; |
983 | anfds [fd].emask = 0; |
1046 | anfds [fd].emask = 0; |
984 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1047 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
985 | } |
1048 | } |
|
|
1049 | } |
|
|
1050 | |
|
|
1051 | /* used to prepare libev internal fd's */ |
|
|
1052 | /* this is not fork-safe */ |
|
|
1053 | inline_speed void |
|
|
1054 | fd_intern (int fd) |
|
|
1055 | { |
|
|
1056 | #ifdef _WIN32 |
|
|
1057 | unsigned long arg = 1; |
|
|
1058 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1059 | #else |
|
|
1060 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1061 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1062 | #endif |
986 | } |
1063 | } |
987 | |
1064 | |
988 | /*****************************************************************************/ |
1065 | /*****************************************************************************/ |
989 | |
1066 | |
990 | /* |
1067 | /* |
… | |
… | |
1064 | |
1141 | |
1065 | for (;;) |
1142 | for (;;) |
1066 | { |
1143 | { |
1067 | int c = k << 1; |
1144 | int c = k << 1; |
1068 | |
1145 | |
1069 | if (c > N + HEAP0 - 1) |
1146 | if (c >= N + HEAP0) |
1070 | break; |
1147 | break; |
1071 | |
1148 | |
1072 | c += c + 1 < N + HEAP0 && ANHE_at (heap [c]) > ANHE_at (heap [c + 1]) |
1149 | c += c + 1 < N + HEAP0 && ANHE_at (heap [c]) > ANHE_at (heap [c + 1]) |
1073 | ? 1 : 0; |
1150 | ? 1 : 0; |
1074 | |
1151 | |
… | |
… | |
1110 | |
1187 | |
1111 | /* move an element suitably so it is in a correct place */ |
1188 | /* move an element suitably so it is in a correct place */ |
1112 | inline_size void |
1189 | inline_size void |
1113 | adjustheap (ANHE *heap, int N, int k) |
1190 | adjustheap (ANHE *heap, int N, int k) |
1114 | { |
1191 | { |
1115 | if (k > HEAP0 && ANHE_at (heap [HPARENT (k)]) >= ANHE_at (heap [k])) |
1192 | if (k > HEAP0 && ANHE_at (heap [k]) <= ANHE_at (heap [HPARENT (k)])) |
1116 | upheap (heap, k); |
1193 | upheap (heap, k); |
1117 | else |
1194 | else |
1118 | downheap (heap, N, k); |
1195 | downheap (heap, N, k); |
1119 | } |
1196 | } |
1120 | |
1197 | |
… | |
… | |
1133 | /*****************************************************************************/ |
1210 | /*****************************************************************************/ |
1134 | |
1211 | |
1135 | /* associate signal watchers to a signal signal */ |
1212 | /* associate signal watchers to a signal signal */ |
1136 | typedef struct |
1213 | typedef struct |
1137 | { |
1214 | { |
|
|
1215 | EV_ATOMIC_T pending; |
|
|
1216 | #if EV_MULTIPLICITY |
|
|
1217 | EV_P; |
|
|
1218 | #endif |
1138 | WL head; |
1219 | WL head; |
1139 | EV_ATOMIC_T gotsig; |
|
|
1140 | } ANSIG; |
1220 | } ANSIG; |
1141 | |
1221 | |
1142 | static ANSIG *signals; |
1222 | static ANSIG signals [EV_NSIG - 1]; |
1143 | static int signalmax; |
|
|
1144 | |
|
|
1145 | static EV_ATOMIC_T gotsig; |
|
|
1146 | |
1223 | |
1147 | /*****************************************************************************/ |
1224 | /*****************************************************************************/ |
1148 | |
1225 | |
1149 | /* used to prepare libev internal fd's */ |
1226 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1150 | /* this is not fork-safe */ |
|
|
1151 | inline_speed void |
|
|
1152 | fd_intern (int fd) |
|
|
1153 | { |
|
|
1154 | #ifdef _WIN32 |
|
|
1155 | unsigned long arg = 1; |
|
|
1156 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
|
|
1157 | #else |
|
|
1158 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1159 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1160 | #endif |
|
|
1161 | } |
|
|
1162 | |
1227 | |
1163 | static void noinline |
1228 | static void noinline |
1164 | evpipe_init (EV_P) |
1229 | evpipe_init (EV_P) |
1165 | { |
1230 | { |
1166 | if (!ev_is_active (&pipe_w)) |
1231 | if (!ev_is_active (&pipe_w)) |
1167 | { |
1232 | { |
1168 | #if EV_USE_EVENTFD |
1233 | # if EV_USE_EVENTFD |
1169 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1234 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1170 | if (evfd < 0 && errno == EINVAL) |
1235 | if (evfd < 0 && errno == EINVAL) |
1171 | evfd = eventfd (0, 0); |
1236 | evfd = eventfd (0, 0); |
1172 | |
1237 | |
1173 | if (evfd >= 0) |
1238 | if (evfd >= 0) |
… | |
… | |
1175 | evpipe [0] = -1; |
1240 | evpipe [0] = -1; |
1176 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1241 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1177 | ev_io_set (&pipe_w, evfd, EV_READ); |
1242 | ev_io_set (&pipe_w, evfd, EV_READ); |
1178 | } |
1243 | } |
1179 | else |
1244 | else |
1180 | #endif |
1245 | # endif |
1181 | { |
1246 | { |
1182 | while (pipe (evpipe)) |
1247 | while (pipe (evpipe)) |
1183 | ev_syserr ("(libev) error creating signal/async pipe"); |
1248 | ev_syserr ("(libev) error creating signal/async pipe"); |
1184 | |
1249 | |
1185 | fd_intern (evpipe [0]); |
1250 | fd_intern (evpipe [0]); |
… | |
… | |
1196 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1261 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1197 | { |
1262 | { |
1198 | if (!*flag) |
1263 | if (!*flag) |
1199 | { |
1264 | { |
1200 | int old_errno = errno; /* save errno because write might clobber it */ |
1265 | int old_errno = errno; /* save errno because write might clobber it */ |
|
|
1266 | char dummy; |
1201 | |
1267 | |
1202 | *flag = 1; |
1268 | *flag = 1; |
1203 | |
1269 | |
1204 | #if EV_USE_EVENTFD |
1270 | #if EV_USE_EVENTFD |
1205 | if (evfd >= 0) |
1271 | if (evfd >= 0) |
… | |
… | |
1207 | uint64_t counter = 1; |
1273 | uint64_t counter = 1; |
1208 | write (evfd, &counter, sizeof (uint64_t)); |
1274 | write (evfd, &counter, sizeof (uint64_t)); |
1209 | } |
1275 | } |
1210 | else |
1276 | else |
1211 | #endif |
1277 | #endif |
1212 | write (evpipe [1], &old_errno, 1); |
1278 | write (evpipe [1], &dummy, 1); |
1213 | |
1279 | |
1214 | errno = old_errno; |
1280 | errno = old_errno; |
1215 | } |
1281 | } |
1216 | } |
1282 | } |
1217 | |
1283 | |
1218 | /* called whenever the libev signal pipe */ |
1284 | /* called whenever the libev signal pipe */ |
1219 | /* got some events (signal, async) */ |
1285 | /* got some events (signal, async) */ |
1220 | static void |
1286 | static void |
1221 | pipecb (EV_P_ ev_io *iow, int revents) |
1287 | pipecb (EV_P_ ev_io *iow, int revents) |
1222 | { |
1288 | { |
|
|
1289 | int i; |
|
|
1290 | |
1223 | #if EV_USE_EVENTFD |
1291 | #if EV_USE_EVENTFD |
1224 | if (evfd >= 0) |
1292 | if (evfd >= 0) |
1225 | { |
1293 | { |
1226 | uint64_t counter; |
1294 | uint64_t counter; |
1227 | read (evfd, &counter, sizeof (uint64_t)); |
1295 | read (evfd, &counter, sizeof (uint64_t)); |
… | |
… | |
1231 | { |
1299 | { |
1232 | char dummy; |
1300 | char dummy; |
1233 | read (evpipe [0], &dummy, 1); |
1301 | read (evpipe [0], &dummy, 1); |
1234 | } |
1302 | } |
1235 | |
1303 | |
1236 | if (gotsig && ev_is_default_loop (EV_A)) |
1304 | if (sig_pending) |
1237 | { |
1305 | { |
1238 | int signum; |
1306 | sig_pending = 0; |
1239 | gotsig = 0; |
|
|
1240 | |
1307 | |
1241 | for (signum = signalmax; signum--; ) |
1308 | for (i = EV_NSIG - 1; i--; ) |
1242 | if (signals [signum].gotsig) |
1309 | if (expect_false (signals [i].pending)) |
1243 | ev_feed_signal_event (EV_A_ signum + 1); |
1310 | ev_feed_signal_event (EV_A_ i + 1); |
1244 | } |
1311 | } |
1245 | |
1312 | |
1246 | #if EV_ASYNC_ENABLE |
1313 | #if EV_ASYNC_ENABLE |
1247 | if (gotasync) |
1314 | if (async_pending) |
1248 | { |
1315 | { |
1249 | int i; |
1316 | async_pending = 0; |
1250 | gotasync = 0; |
|
|
1251 | |
1317 | |
1252 | for (i = asynccnt; i--; ) |
1318 | for (i = asynccnt; i--; ) |
1253 | if (asyncs [i]->sent) |
1319 | if (asyncs [i]->sent) |
1254 | { |
1320 | { |
1255 | asyncs [i]->sent = 0; |
1321 | asyncs [i]->sent = 0; |
… | |
… | |
1263 | |
1329 | |
1264 | static void |
1330 | static void |
1265 | ev_sighandler (int signum) |
1331 | ev_sighandler (int signum) |
1266 | { |
1332 | { |
1267 | #if EV_MULTIPLICITY |
1333 | #if EV_MULTIPLICITY |
1268 | struct ev_loop *loop = &default_loop_struct; |
1334 | EV_P = signals [signum - 1].loop; |
1269 | #endif |
1335 | #endif |
1270 | |
1336 | |
1271 | #if _WIN32 |
1337 | #ifdef _WIN32 |
1272 | signal (signum, ev_sighandler); |
1338 | signal (signum, ev_sighandler); |
1273 | #endif |
1339 | #endif |
1274 | |
1340 | |
1275 | signals [signum - 1].gotsig = 1; |
1341 | signals [signum - 1].pending = 1; |
1276 | evpipe_write (EV_A_ &gotsig); |
1342 | evpipe_write (EV_A_ &sig_pending); |
1277 | } |
1343 | } |
1278 | |
1344 | |
1279 | void noinline |
1345 | void noinline |
1280 | ev_feed_signal_event (EV_P_ int signum) |
1346 | ev_feed_signal_event (EV_P_ int signum) |
1281 | { |
1347 | { |
1282 | WL w; |
1348 | WL w; |
1283 | |
1349 | |
|
|
1350 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
|
|
1351 | return; |
|
|
1352 | |
|
|
1353 | --signum; |
|
|
1354 | |
1284 | #if EV_MULTIPLICITY |
1355 | #if EV_MULTIPLICITY |
1285 | assert (("libev: feeding signal events is only supported in the default loop", loop == ev_default_loop_ptr)); |
1356 | /* it is permissible to try to feed a signal to the wrong loop */ |
1286 | #endif |
1357 | /* or, likely more useful, feeding a signal nobody is waiting for */ |
1287 | |
1358 | |
1288 | --signum; |
1359 | if (expect_false (signals [signum].loop != EV_A)) |
1289 | |
|
|
1290 | if (signum < 0 || signum >= signalmax) |
|
|
1291 | return; |
1360 | return; |
|
|
1361 | #endif |
1292 | |
1362 | |
1293 | signals [signum].gotsig = 0; |
1363 | signals [signum].pending = 0; |
1294 | |
1364 | |
1295 | for (w = signals [signum].head; w; w = w->next) |
1365 | for (w = signals [signum].head; w; w = w->next) |
1296 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
1366 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
1297 | } |
1367 | } |
1298 | |
1368 | |
1299 | #if EV_USE_SIGNALFD |
1369 | #if EV_USE_SIGNALFD |
1300 | static void |
1370 | static void |
1301 | sigfdcb (EV_P_ ev_io *iow, int revents) |
1371 | sigfdcb (EV_P_ ev_io *iow, int revents) |
1302 | { |
1372 | { |
1303 | struct signalfd_siginfo si[4], *sip; |
1373 | struct signalfd_siginfo si[2], *sip; /* these structs are big */ |
1304 | |
1374 | |
1305 | for (;;) |
1375 | for (;;) |
1306 | { |
1376 | { |
1307 | ssize_t res = read (sigfd, si, sizeof (si)); |
1377 | ssize_t res = read (sigfd, si, sizeof (si)); |
1308 | |
1378 | |
… | |
… | |
1314 | break; |
1384 | break; |
1315 | } |
1385 | } |
1316 | } |
1386 | } |
1317 | #endif |
1387 | #endif |
1318 | |
1388 | |
|
|
1389 | #endif |
|
|
1390 | |
1319 | /*****************************************************************************/ |
1391 | /*****************************************************************************/ |
1320 | |
1392 | |
|
|
1393 | #if EV_CHILD_ENABLE |
1321 | static WL childs [EV_PID_HASHSIZE]; |
1394 | static WL childs [EV_PID_HASHSIZE]; |
1322 | |
|
|
1323 | #ifndef _WIN32 |
|
|
1324 | |
1395 | |
1325 | static ev_signal childev; |
1396 | static ev_signal childev; |
1326 | |
1397 | |
1327 | #ifndef WIFCONTINUED |
1398 | #ifndef WIFCONTINUED |
1328 | # define WIFCONTINUED(status) 0 |
1399 | # define WIFCONTINUED(status) 0 |
… | |
… | |
1333 | child_reap (EV_P_ int chain, int pid, int status) |
1404 | child_reap (EV_P_ int chain, int pid, int status) |
1334 | { |
1405 | { |
1335 | ev_child *w; |
1406 | ev_child *w; |
1336 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1407 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1337 | |
1408 | |
1338 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1409 | for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next) |
1339 | { |
1410 | { |
1340 | if ((w->pid == pid || !w->pid) |
1411 | if ((w->pid == pid || !w->pid) |
1341 | && (!traced || (w->flags & 1))) |
1412 | && (!traced || (w->flags & 1))) |
1342 | { |
1413 | { |
1343 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
1414 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
… | |
… | |
1368 | /* make sure we are called again until all children have been reaped */ |
1439 | /* make sure we are called again until all children have been reaped */ |
1369 | /* we need to do it this way so that the callback gets called before we continue */ |
1440 | /* we need to do it this way so that the callback gets called before we continue */ |
1370 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1441 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1371 | |
1442 | |
1372 | child_reap (EV_A_ pid, pid, status); |
1443 | child_reap (EV_A_ pid, pid, status); |
1373 | if (EV_PID_HASHSIZE > 1) |
1444 | if ((EV_PID_HASHSIZE) > 1) |
1374 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1445 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1375 | } |
1446 | } |
1376 | |
1447 | |
1377 | #endif |
1448 | #endif |
1378 | |
1449 | |
… | |
… | |
1445 | #ifdef __APPLE__ |
1516 | #ifdef __APPLE__ |
1446 | /* only select works correctly on that "unix-certified" platform */ |
1517 | /* only select works correctly on that "unix-certified" platform */ |
1447 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1518 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1448 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1519 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1449 | #endif |
1520 | #endif |
|
|
1521 | #ifdef __FreeBSD__ |
|
|
1522 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
|
|
1523 | #endif |
1450 | |
1524 | |
1451 | return flags; |
1525 | return flags; |
1452 | } |
1526 | } |
1453 | |
1527 | |
1454 | unsigned int |
1528 | unsigned int |
… | |
… | |
1467 | ev_backend (EV_P) |
1541 | ev_backend (EV_P) |
1468 | { |
1542 | { |
1469 | return backend; |
1543 | return backend; |
1470 | } |
1544 | } |
1471 | |
1545 | |
1472 | #if EV_MINIMAL < 2 |
1546 | #if EV_FEATURE_API |
1473 | unsigned int |
1547 | unsigned int |
1474 | ev_loop_count (EV_P) |
1548 | ev_iteration (EV_P) |
1475 | { |
1549 | { |
1476 | return loop_count; |
1550 | return loop_count; |
1477 | } |
1551 | } |
1478 | |
1552 | |
1479 | unsigned int |
1553 | unsigned int |
1480 | ev_loop_depth (EV_P) |
1554 | ev_depth (EV_P) |
1481 | { |
1555 | { |
1482 | return loop_depth; |
1556 | return loop_depth; |
1483 | } |
1557 | } |
1484 | |
1558 | |
1485 | void |
1559 | void |
… | |
… | |
1542 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
1616 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
1543 | have_monotonic = 1; |
1617 | have_monotonic = 1; |
1544 | } |
1618 | } |
1545 | #endif |
1619 | #endif |
1546 | |
1620 | |
|
|
1621 | /* pid check not overridable via env */ |
|
|
1622 | #ifndef _WIN32 |
|
|
1623 | if (flags & EVFLAG_FORKCHECK) |
|
|
1624 | curpid = getpid (); |
|
|
1625 | #endif |
|
|
1626 | |
|
|
1627 | if (!(flags & EVFLAG_NOENV) |
|
|
1628 | && !enable_secure () |
|
|
1629 | && getenv ("LIBEV_FLAGS")) |
|
|
1630 | flags = atoi (getenv ("LIBEV_FLAGS")); |
|
|
1631 | |
1547 | ev_rt_now = ev_time (); |
1632 | ev_rt_now = ev_time (); |
1548 | mn_now = get_clock (); |
1633 | mn_now = get_clock (); |
1549 | now_floor = mn_now; |
1634 | now_floor = mn_now; |
1550 | rtmn_diff = ev_rt_now - mn_now; |
1635 | rtmn_diff = ev_rt_now - mn_now; |
1551 | #if EV_MINIMAL < 2 |
1636 | #if EV_FEATURE_API |
1552 | invoke_cb = ev_invoke_pending; |
1637 | invoke_cb = ev_invoke_pending; |
1553 | #endif |
1638 | #endif |
1554 | |
1639 | |
1555 | io_blocktime = 0.; |
1640 | io_blocktime = 0.; |
1556 | timeout_blocktime = 0.; |
1641 | timeout_blocktime = 0.; |
1557 | backend = 0; |
1642 | backend = 0; |
1558 | backend_fd = -1; |
1643 | backend_fd = -1; |
1559 | gotasync = 0; |
1644 | sig_pending = 0; |
|
|
1645 | #if EV_ASYNC_ENABLE |
|
|
1646 | async_pending = 0; |
|
|
1647 | #endif |
1560 | #if EV_USE_INOTIFY |
1648 | #if EV_USE_INOTIFY |
1561 | fs_fd = -2; |
1649 | fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2; |
1562 | #endif |
1650 | #endif |
1563 | #if EV_USE_SIGNALFD |
1651 | #if EV_USE_SIGNALFD |
1564 | sigfd = -2; |
1652 | sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1; |
1565 | #endif |
1653 | #endif |
1566 | |
|
|
1567 | /* pid check not overridable via env */ |
|
|
1568 | #ifndef _WIN32 |
|
|
1569 | if (flags & EVFLAG_FORKCHECK) |
|
|
1570 | curpid = getpid (); |
|
|
1571 | #endif |
|
|
1572 | |
|
|
1573 | if (!(flags & EVFLAG_NOENV) |
|
|
1574 | && !enable_secure () |
|
|
1575 | && getenv ("LIBEV_FLAGS")) |
|
|
1576 | flags = atoi (getenv ("LIBEV_FLAGS")); |
|
|
1577 | |
1654 | |
1578 | if (!(flags & 0x0000ffffU)) |
1655 | if (!(flags & 0x0000ffffU)) |
1579 | flags |= ev_recommended_backends (); |
1656 | flags |= ev_recommended_backends (); |
1580 | |
1657 | |
1581 | #if EV_USE_PORT |
1658 | #if EV_USE_PORT |
… | |
… | |
1594 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1671 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1595 | #endif |
1672 | #endif |
1596 | |
1673 | |
1597 | ev_prepare_init (&pending_w, pendingcb); |
1674 | ev_prepare_init (&pending_w, pendingcb); |
1598 | |
1675 | |
|
|
1676 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1599 | ev_init (&pipe_w, pipecb); |
1677 | ev_init (&pipe_w, pipecb); |
1600 | ev_set_priority (&pipe_w, EV_MAXPRI); |
1678 | ev_set_priority (&pipe_w, EV_MAXPRI); |
|
|
1679 | #endif |
1601 | } |
1680 | } |
1602 | } |
1681 | } |
1603 | |
1682 | |
1604 | /* free up a loop structure */ |
1683 | /* free up a loop structure */ |
1605 | static void noinline |
1684 | static void noinline |
… | |
… | |
1617 | close (evfd); |
1696 | close (evfd); |
1618 | #endif |
1697 | #endif |
1619 | |
1698 | |
1620 | if (evpipe [0] >= 0) |
1699 | if (evpipe [0] >= 0) |
1621 | { |
1700 | { |
1622 | close (evpipe [0]); |
1701 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1623 | close (evpipe [1]); |
1702 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1624 | } |
1703 | } |
1625 | } |
1704 | } |
1626 | |
1705 | |
1627 | #if EV_USE_SIGNALFD |
1706 | #if EV_USE_SIGNALFD |
1628 | if (ev_is_active (&sigfd_w)) |
1707 | if (ev_is_active (&sigfd_w)) |
1629 | { |
|
|
1630 | /*ev_ref (EV_A);*/ |
|
|
1631 | /*ev_io_stop (EV_A_ &sigfd_w);*/ |
|
|
1632 | |
|
|
1633 | close (sigfd); |
1708 | close (sigfd); |
1634 | } |
|
|
1635 | #endif |
1709 | #endif |
1636 | |
1710 | |
1637 | #if EV_USE_INOTIFY |
1711 | #if EV_USE_INOTIFY |
1638 | if (fs_fd >= 0) |
1712 | if (fs_fd >= 0) |
1639 | close (fs_fd); |
1713 | close (fs_fd); |
… | |
… | |
1709 | |
1783 | |
1710 | if (ev_is_active (&pipe_w)) |
1784 | if (ev_is_active (&pipe_w)) |
1711 | { |
1785 | { |
1712 | /* this "locks" the handlers against writing to the pipe */ |
1786 | /* this "locks" the handlers against writing to the pipe */ |
1713 | /* while we modify the fd vars */ |
1787 | /* while we modify the fd vars */ |
1714 | gotsig = 1; |
1788 | sig_pending = 1; |
1715 | #if EV_ASYNC_ENABLE |
1789 | #if EV_ASYNC_ENABLE |
1716 | gotasync = 1; |
1790 | async_pending = 1; |
1717 | #endif |
1791 | #endif |
1718 | |
1792 | |
1719 | ev_ref (EV_A); |
1793 | ev_ref (EV_A); |
1720 | ev_io_stop (EV_A_ &pipe_w); |
1794 | ev_io_stop (EV_A_ &pipe_w); |
1721 | |
1795 | |
… | |
… | |
1724 | close (evfd); |
1798 | close (evfd); |
1725 | #endif |
1799 | #endif |
1726 | |
1800 | |
1727 | if (evpipe [0] >= 0) |
1801 | if (evpipe [0] >= 0) |
1728 | { |
1802 | { |
1729 | close (evpipe [0]); |
1803 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1730 | close (evpipe [1]); |
1804 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1731 | } |
1805 | } |
1732 | |
1806 | |
|
|
1807 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1733 | evpipe_init (EV_A); |
1808 | evpipe_init (EV_A); |
1734 | /* now iterate over everything, in case we missed something */ |
1809 | /* now iterate over everything, in case we missed something */ |
1735 | pipecb (EV_A_ &pipe_w, EV_READ); |
1810 | pipecb (EV_A_ &pipe_w, EV_READ); |
|
|
1811 | #endif |
1736 | } |
1812 | } |
1737 | |
1813 | |
1738 | postfork = 0; |
1814 | postfork = 0; |
1739 | } |
1815 | } |
1740 | |
1816 | |
1741 | #if EV_MULTIPLICITY |
1817 | #if EV_MULTIPLICITY |
1742 | |
1818 | |
1743 | struct ev_loop * |
1819 | struct ev_loop * |
1744 | ev_loop_new (unsigned int flags) |
1820 | ev_loop_new (unsigned int flags) |
1745 | { |
1821 | { |
1746 | struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
1822 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
1747 | |
1823 | |
1748 | memset (loop, 0, sizeof (struct ev_loop)); |
1824 | memset (EV_A, 0, sizeof (struct ev_loop)); |
1749 | loop_init (EV_A_ flags); |
1825 | loop_init (EV_A_ flags); |
1750 | |
1826 | |
1751 | if (ev_backend (EV_A)) |
1827 | if (ev_backend (EV_A)) |
1752 | return loop; |
1828 | return EV_A; |
1753 | |
1829 | |
1754 | return 0; |
1830 | return 0; |
1755 | } |
1831 | } |
1756 | |
1832 | |
1757 | void |
1833 | void |
… | |
… | |
1802 | verify_watcher (EV_A_ ws [cnt]); |
1878 | verify_watcher (EV_A_ ws [cnt]); |
1803 | } |
1879 | } |
1804 | } |
1880 | } |
1805 | #endif |
1881 | #endif |
1806 | |
1882 | |
1807 | #if EV_MINIMAL < 2 |
1883 | #if EV_FEATURE_API |
1808 | void |
1884 | void |
1809 | ev_loop_verify (EV_P) |
1885 | ev_verify (EV_P) |
1810 | { |
1886 | { |
1811 | #if EV_VERIFY |
1887 | #if EV_VERIFY |
1812 | int i; |
1888 | int i; |
1813 | WL w; |
1889 | WL w; |
1814 | |
1890 | |
… | |
… | |
1853 | #if EV_ASYNC_ENABLE |
1929 | #if EV_ASYNC_ENABLE |
1854 | assert (asyncmax >= asynccnt); |
1930 | assert (asyncmax >= asynccnt); |
1855 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1931 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1856 | #endif |
1932 | #endif |
1857 | |
1933 | |
|
|
1934 | #if EV_PREPARE_ENABLE |
1858 | assert (preparemax >= preparecnt); |
1935 | assert (preparemax >= preparecnt); |
1859 | array_verify (EV_A_ (W *)prepares, preparecnt); |
1936 | array_verify (EV_A_ (W *)prepares, preparecnt); |
|
|
1937 | #endif |
1860 | |
1938 | |
|
|
1939 | #if EV_CHECK_ENABLE |
1861 | assert (checkmax >= checkcnt); |
1940 | assert (checkmax >= checkcnt); |
1862 | array_verify (EV_A_ (W *)checks, checkcnt); |
1941 | array_verify (EV_A_ (W *)checks, checkcnt); |
|
|
1942 | #endif |
1863 | |
1943 | |
1864 | # if 0 |
1944 | # if 0 |
|
|
1945 | #if EV_CHILD_ENABLE |
1865 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1946 | for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next) |
1866 | for (signum = signalmax; signum--; ) if (signals [signum].gotsig) |
1947 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
|
|
1948 | #endif |
1867 | # endif |
1949 | # endif |
1868 | #endif |
1950 | #endif |
1869 | } |
1951 | } |
1870 | #endif |
1952 | #endif |
1871 | |
1953 | |
… | |
… | |
1878 | #endif |
1960 | #endif |
1879 | { |
1961 | { |
1880 | if (!ev_default_loop_ptr) |
1962 | if (!ev_default_loop_ptr) |
1881 | { |
1963 | { |
1882 | #if EV_MULTIPLICITY |
1964 | #if EV_MULTIPLICITY |
1883 | struct ev_loop *loop = ev_default_loop_ptr = &default_loop_struct; |
1965 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
1884 | #else |
1966 | #else |
1885 | ev_default_loop_ptr = 1; |
1967 | ev_default_loop_ptr = 1; |
1886 | #endif |
1968 | #endif |
1887 | |
1969 | |
1888 | loop_init (EV_A_ flags); |
1970 | loop_init (EV_A_ flags); |
1889 | |
1971 | |
1890 | if (ev_backend (EV_A)) |
1972 | if (ev_backend (EV_A)) |
1891 | { |
1973 | { |
1892 | #ifndef _WIN32 |
1974 | #if EV_CHILD_ENABLE |
1893 | ev_signal_init (&childev, childcb, SIGCHLD); |
1975 | ev_signal_init (&childev, childcb, SIGCHLD); |
1894 | ev_set_priority (&childev, EV_MAXPRI); |
1976 | ev_set_priority (&childev, EV_MAXPRI); |
1895 | ev_signal_start (EV_A_ &childev); |
1977 | ev_signal_start (EV_A_ &childev); |
1896 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1978 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1897 | #endif |
1979 | #endif |
… | |
… | |
1905 | |
1987 | |
1906 | void |
1988 | void |
1907 | ev_default_destroy (void) |
1989 | ev_default_destroy (void) |
1908 | { |
1990 | { |
1909 | #if EV_MULTIPLICITY |
1991 | #if EV_MULTIPLICITY |
1910 | struct ev_loop *loop = ev_default_loop_ptr; |
1992 | EV_P = ev_default_loop_ptr; |
1911 | #endif |
1993 | #endif |
1912 | |
1994 | |
1913 | ev_default_loop_ptr = 0; |
1995 | ev_default_loop_ptr = 0; |
1914 | |
1996 | |
1915 | #ifndef _WIN32 |
1997 | #if EV_CHILD_ENABLE |
1916 | ev_ref (EV_A); /* child watcher */ |
1998 | ev_ref (EV_A); /* child watcher */ |
1917 | ev_signal_stop (EV_A_ &childev); |
1999 | ev_signal_stop (EV_A_ &childev); |
1918 | #endif |
2000 | #endif |
1919 | |
2001 | |
1920 | loop_destroy (EV_A); |
2002 | loop_destroy (EV_A); |
… | |
… | |
1922 | |
2004 | |
1923 | void |
2005 | void |
1924 | ev_default_fork (void) |
2006 | ev_default_fork (void) |
1925 | { |
2007 | { |
1926 | #if EV_MULTIPLICITY |
2008 | #if EV_MULTIPLICITY |
1927 | struct ev_loop *loop = ev_default_loop_ptr; |
2009 | EV_P = ev_default_loop_ptr; |
1928 | #endif |
2010 | #endif |
1929 | |
2011 | |
1930 | postfork = 1; /* must be in line with ev_loop_fork */ |
2012 | postfork = 1; /* must be in line with ev_loop_fork */ |
1931 | } |
2013 | } |
1932 | |
2014 | |
… | |
… | |
2026 | EV_FREQUENT_CHECK; |
2108 | EV_FREQUENT_CHECK; |
2027 | feed_reverse (EV_A_ (W)w); |
2109 | feed_reverse (EV_A_ (W)w); |
2028 | } |
2110 | } |
2029 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2111 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2030 | |
2112 | |
2031 | feed_reverse_done (EV_A_ EV_TIMEOUT); |
2113 | feed_reverse_done (EV_A_ EV_TIMER); |
2032 | } |
2114 | } |
2033 | } |
2115 | } |
2034 | |
2116 | |
2035 | #if EV_PERIODIC_ENABLE |
2117 | #if EV_PERIODIC_ENABLE |
2036 | /* make periodics pending */ |
2118 | /* make periodics pending */ |
… | |
… | |
2127 | ANHE_at_cache (*he); |
2209 | ANHE_at_cache (*he); |
2128 | } |
2210 | } |
2129 | } |
2211 | } |
2130 | |
2212 | |
2131 | /* fetch new monotonic and realtime times from the kernel */ |
2213 | /* fetch new monotonic and realtime times from the kernel */ |
2132 | /* also detetc if there was a timejump, and act accordingly */ |
2214 | /* also detect if there was a timejump, and act accordingly */ |
2133 | inline_speed void |
2215 | inline_speed void |
2134 | time_update (EV_P_ ev_tstamp max_block) |
2216 | time_update (EV_P_ ev_tstamp max_block) |
2135 | { |
2217 | { |
2136 | #if EV_USE_MONOTONIC |
2218 | #if EV_USE_MONOTONIC |
2137 | if (expect_true (have_monotonic)) |
2219 | if (expect_true (have_monotonic)) |
… | |
… | |
2197 | } |
2279 | } |
2198 | |
2280 | |
2199 | void |
2281 | void |
2200 | ev_loop (EV_P_ int flags) |
2282 | ev_loop (EV_P_ int flags) |
2201 | { |
2283 | { |
2202 | #if EV_MINIMAL < 2 |
2284 | #if EV_FEATURE_API |
2203 | ++loop_depth; |
2285 | ++loop_depth; |
2204 | #endif |
2286 | #endif |
2205 | |
2287 | |
2206 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2288 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2207 | |
2289 | |
… | |
… | |
2210 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2292 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2211 | |
2293 | |
2212 | do |
2294 | do |
2213 | { |
2295 | { |
2214 | #if EV_VERIFY >= 2 |
2296 | #if EV_VERIFY >= 2 |
2215 | ev_loop_verify (EV_A); |
2297 | ev_verify (EV_A); |
2216 | #endif |
2298 | #endif |
2217 | |
2299 | |
2218 | #ifndef _WIN32 |
2300 | #ifndef _WIN32 |
2219 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2301 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2220 | if (expect_false (getpid () != curpid)) |
2302 | if (expect_false (getpid () != curpid)) |
… | |
… | |
2232 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2314 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2233 | EV_INVOKE_PENDING; |
2315 | EV_INVOKE_PENDING; |
2234 | } |
2316 | } |
2235 | #endif |
2317 | #endif |
2236 | |
2318 | |
|
|
2319 | #if EV_PREPARE_ENABLE |
2237 | /* queue prepare watchers (and execute them) */ |
2320 | /* queue prepare watchers (and execute them) */ |
2238 | if (expect_false (preparecnt)) |
2321 | if (expect_false (preparecnt)) |
2239 | { |
2322 | { |
2240 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2323 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2241 | EV_INVOKE_PENDING; |
2324 | EV_INVOKE_PENDING; |
2242 | } |
2325 | } |
|
|
2326 | #endif |
2243 | |
2327 | |
2244 | if (expect_false (loop_done)) |
2328 | if (expect_false (loop_done)) |
2245 | break; |
2329 | break; |
2246 | |
2330 | |
2247 | /* we might have forked, so reify kernel state if necessary */ |
2331 | /* we might have forked, so reify kernel state if necessary */ |
… | |
… | |
2298 | waittime -= sleeptime; |
2382 | waittime -= sleeptime; |
2299 | } |
2383 | } |
2300 | } |
2384 | } |
2301 | } |
2385 | } |
2302 | |
2386 | |
2303 | #if EV_MINIMAL < 2 |
2387 | #if EV_FEATURE_API |
2304 | ++loop_count; |
2388 | ++loop_count; |
2305 | #endif |
2389 | #endif |
2306 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2390 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2307 | backend_poll (EV_A_ waittime); |
2391 | backend_poll (EV_A_ waittime); |
2308 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
2392 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
… | |
… | |
2320 | #if EV_IDLE_ENABLE |
2404 | #if EV_IDLE_ENABLE |
2321 | /* queue idle watchers unless other events are pending */ |
2405 | /* queue idle watchers unless other events are pending */ |
2322 | idle_reify (EV_A); |
2406 | idle_reify (EV_A); |
2323 | #endif |
2407 | #endif |
2324 | |
2408 | |
|
|
2409 | #if EV_CHECK_ENABLE |
2325 | /* queue check watchers, to be executed first */ |
2410 | /* queue check watchers, to be executed first */ |
2326 | if (expect_false (checkcnt)) |
2411 | if (expect_false (checkcnt)) |
2327 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
2412 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
|
|
2413 | #endif |
2328 | |
2414 | |
2329 | EV_INVOKE_PENDING; |
2415 | EV_INVOKE_PENDING; |
2330 | } |
2416 | } |
2331 | while (expect_true ( |
2417 | while (expect_true ( |
2332 | activecnt |
2418 | activecnt |
… | |
… | |
2335 | )); |
2421 | )); |
2336 | |
2422 | |
2337 | if (loop_done == EVUNLOOP_ONE) |
2423 | if (loop_done == EVUNLOOP_ONE) |
2338 | loop_done = EVUNLOOP_CANCEL; |
2424 | loop_done = EVUNLOOP_CANCEL; |
2339 | |
2425 | |
2340 | #if EV_MINIMAL < 2 |
2426 | #if EV_FEATURE_API |
2341 | --loop_depth; |
2427 | --loop_depth; |
2342 | #endif |
2428 | #endif |
2343 | } |
2429 | } |
2344 | |
2430 | |
2345 | void |
2431 | void |
… | |
… | |
2398 | inline_size void |
2484 | inline_size void |
2399 | wlist_del (WL *head, WL elem) |
2485 | wlist_del (WL *head, WL elem) |
2400 | { |
2486 | { |
2401 | while (*head) |
2487 | while (*head) |
2402 | { |
2488 | { |
2403 | if (*head == elem) |
2489 | if (expect_true (*head == elem)) |
2404 | { |
2490 | { |
2405 | *head = elem->next; |
2491 | *head = elem->next; |
2406 | return; |
2492 | break; |
2407 | } |
2493 | } |
2408 | |
2494 | |
2409 | head = &(*head)->next; |
2495 | head = &(*head)->next; |
2410 | } |
2496 | } |
2411 | } |
2497 | } |
… | |
… | |
2471 | |
2557 | |
2472 | if (expect_false (ev_is_active (w))) |
2558 | if (expect_false (ev_is_active (w))) |
2473 | return; |
2559 | return; |
2474 | |
2560 | |
2475 | assert (("libev: ev_io_start called with negative fd", fd >= 0)); |
2561 | assert (("libev: ev_io_start called with negative fd", fd >= 0)); |
2476 | assert (("libev: ev_io start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
2562 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
2477 | |
2563 | |
2478 | EV_FREQUENT_CHECK; |
2564 | EV_FREQUENT_CHECK; |
2479 | |
2565 | |
2480 | ev_start (EV_A_ (W)w, 1); |
2566 | ev_start (EV_A_ (W)w, 1); |
2481 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
2567 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
… | |
… | |
2551 | timers [active] = timers [timercnt + HEAP0]; |
2637 | timers [active] = timers [timercnt + HEAP0]; |
2552 | adjustheap (timers, timercnt, active); |
2638 | adjustheap (timers, timercnt, active); |
2553 | } |
2639 | } |
2554 | } |
2640 | } |
2555 | |
2641 | |
2556 | EV_FREQUENT_CHECK; |
|
|
2557 | |
|
|
2558 | ev_at (w) -= mn_now; |
2642 | ev_at (w) -= mn_now; |
2559 | |
2643 | |
2560 | ev_stop (EV_A_ (W)w); |
2644 | ev_stop (EV_A_ (W)w); |
|
|
2645 | |
|
|
2646 | EV_FREQUENT_CHECK; |
2561 | } |
2647 | } |
2562 | |
2648 | |
2563 | void noinline |
2649 | void noinline |
2564 | ev_timer_again (EV_P_ ev_timer *w) |
2650 | ev_timer_again (EV_P_ ev_timer *w) |
2565 | { |
2651 | { |
… | |
… | |
2644 | periodics [active] = periodics [periodiccnt + HEAP0]; |
2730 | periodics [active] = periodics [periodiccnt + HEAP0]; |
2645 | adjustheap (periodics, periodiccnt, active); |
2731 | adjustheap (periodics, periodiccnt, active); |
2646 | } |
2732 | } |
2647 | } |
2733 | } |
2648 | |
2734 | |
2649 | EV_FREQUENT_CHECK; |
|
|
2650 | |
|
|
2651 | ev_stop (EV_A_ (W)w); |
2735 | ev_stop (EV_A_ (W)w); |
|
|
2736 | |
|
|
2737 | EV_FREQUENT_CHECK; |
2652 | } |
2738 | } |
2653 | |
2739 | |
2654 | void noinline |
2740 | void noinline |
2655 | ev_periodic_again (EV_P_ ev_periodic *w) |
2741 | ev_periodic_again (EV_P_ ev_periodic *w) |
2656 | { |
2742 | { |
… | |
… | |
2662 | |
2748 | |
2663 | #ifndef SA_RESTART |
2749 | #ifndef SA_RESTART |
2664 | # define SA_RESTART 0 |
2750 | # define SA_RESTART 0 |
2665 | #endif |
2751 | #endif |
2666 | |
2752 | |
|
|
2753 | #if EV_SIGNAL_ENABLE |
|
|
2754 | |
2667 | void noinline |
2755 | void noinline |
2668 | ev_signal_start (EV_P_ ev_signal *w) |
2756 | ev_signal_start (EV_P_ ev_signal *w) |
2669 | { |
2757 | { |
2670 | #if EV_MULTIPLICITY |
|
|
2671 | assert (("libev: signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
|
|
2672 | #endif |
|
|
2673 | if (expect_false (ev_is_active (w))) |
2758 | if (expect_false (ev_is_active (w))) |
2674 | return; |
2759 | return; |
2675 | |
2760 | |
2676 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0)); |
2761 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
|
|
2762 | |
|
|
2763 | #if EV_MULTIPLICITY |
|
|
2764 | assert (("libev: a signal must not be attached to two different loops", |
|
|
2765 | !signals [w->signum - 1].loop || signals [w->signum - 1].loop == loop)); |
|
|
2766 | |
|
|
2767 | signals [w->signum - 1].loop = EV_A; |
|
|
2768 | #endif |
2677 | |
2769 | |
2678 | EV_FREQUENT_CHECK; |
2770 | EV_FREQUENT_CHECK; |
2679 | |
2771 | |
2680 | #if EV_USE_SIGNALFD |
2772 | #if EV_USE_SIGNALFD |
2681 | if (sigfd == -2) |
2773 | if (sigfd == -2) |
… | |
… | |
2703 | sigaddset (&sigfd_set, w->signum); |
2795 | sigaddset (&sigfd_set, w->signum); |
2704 | sigprocmask (SIG_BLOCK, &sigfd_set, 0); |
2796 | sigprocmask (SIG_BLOCK, &sigfd_set, 0); |
2705 | |
2797 | |
2706 | signalfd (sigfd, &sigfd_set, 0); |
2798 | signalfd (sigfd, &sigfd_set, 0); |
2707 | } |
2799 | } |
2708 | else |
|
|
2709 | #endif |
|
|
2710 | evpipe_init (EV_A); |
|
|
2711 | |
|
|
2712 | { |
|
|
2713 | #ifndef _WIN32 |
|
|
2714 | sigset_t full, prev; |
|
|
2715 | sigfillset (&full); |
|
|
2716 | sigprocmask (SIG_SETMASK, &full, &prev); |
|
|
2717 | #endif |
|
|
2718 | |
|
|
2719 | array_needsize (ANSIG, signals, signalmax, w->signum, array_init_zero); |
|
|
2720 | |
|
|
2721 | #ifndef _WIN32 |
|
|
2722 | # if EV_USE_SIGNALFD |
|
|
2723 | if (sigfd < 0)/*TODO*/ |
|
|
2724 | # endif |
2800 | #endif |
2725 | sigdelset (&prev, w->signum); |
|
|
2726 | sigprocmask (SIG_SETMASK, &prev, 0); |
|
|
2727 | #endif |
|
|
2728 | } |
|
|
2729 | |
2801 | |
2730 | ev_start (EV_A_ (W)w, 1); |
2802 | ev_start (EV_A_ (W)w, 1); |
2731 | wlist_add (&signals [w->signum - 1].head, (WL)w); |
2803 | wlist_add (&signals [w->signum - 1].head, (WL)w); |
2732 | |
2804 | |
2733 | if (!((WL)w)->next) |
2805 | if (!((WL)w)->next) |
2734 | { |
|
|
2735 | #if _WIN32 |
|
|
2736 | signal (w->signum, ev_sighandler); |
|
|
2737 | #else |
|
|
2738 | # if EV_USE_SIGNALFD |
2806 | # if EV_USE_SIGNALFD |
2739 | if (sigfd < 0) /*TODO*/ |
2807 | if (sigfd < 0) /*TODO*/ |
2740 | # endif |
2808 | # endif |
2741 | { |
2809 | { |
|
|
2810 | # ifdef _WIN32 |
|
|
2811 | evpipe_init (EV_A); |
|
|
2812 | |
|
|
2813 | signal (w->signum, ev_sighandler); |
|
|
2814 | # else |
2742 | struct sigaction sa = { }; |
2815 | struct sigaction sa; |
|
|
2816 | |
|
|
2817 | evpipe_init (EV_A); |
|
|
2818 | |
2743 | sa.sa_handler = ev_sighandler; |
2819 | sa.sa_handler = ev_sighandler; |
2744 | sigfillset (&sa.sa_mask); |
2820 | sigfillset (&sa.sa_mask); |
2745 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
2821 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
2746 | sigaction (w->signum, &sa, 0); |
2822 | sigaction (w->signum, &sa, 0); |
|
|
2823 | |
|
|
2824 | sigemptyset (&sa.sa_mask); |
|
|
2825 | sigaddset (&sa.sa_mask, w->signum); |
|
|
2826 | sigprocmask (SIG_UNBLOCK, &sa.sa_mask, 0); |
|
|
2827 | #endif |
2747 | } |
2828 | } |
2748 | #endif |
|
|
2749 | } |
|
|
2750 | |
2829 | |
2751 | EV_FREQUENT_CHECK; |
2830 | EV_FREQUENT_CHECK; |
2752 | } |
2831 | } |
2753 | |
2832 | |
2754 | void noinline |
2833 | void noinline |
… | |
… | |
2762 | |
2841 | |
2763 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
2842 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
2764 | ev_stop (EV_A_ (W)w); |
2843 | ev_stop (EV_A_ (W)w); |
2765 | |
2844 | |
2766 | if (!signals [w->signum - 1].head) |
2845 | if (!signals [w->signum - 1].head) |
|
|
2846 | { |
|
|
2847 | #if EV_MULTIPLICITY |
|
|
2848 | signals [w->signum - 1].loop = 0; /* unattach from signal */ |
|
|
2849 | #endif |
2767 | #if EV_USE_SIGNALFD |
2850 | #if EV_USE_SIGNALFD |
2768 | if (sigfd >= 0) |
2851 | if (sigfd >= 0) |
2769 | { |
2852 | { |
2770 | sigprocmask (SIG_UNBLOCK, &sigfd_set, 0);//D |
2853 | sigset_t ss; |
|
|
2854 | |
|
|
2855 | sigemptyset (&ss); |
|
|
2856 | sigaddset (&ss, w->signum); |
2771 | sigdelset (&sigfd_set, w->signum); |
2857 | sigdelset (&sigfd_set, w->signum); |
|
|
2858 | |
2772 | signalfd (sigfd, &sigfd_set, 0); |
2859 | signalfd (sigfd, &sigfd_set, 0); |
2773 | sigprocmask (SIG_BLOCK, &sigfd_set, 0);//D |
2860 | sigprocmask (SIG_UNBLOCK, &ss, 0); |
2774 | /*TODO: maybe unblock signal? */ |
|
|
2775 | } |
2861 | } |
2776 | else |
2862 | else |
2777 | #endif |
2863 | #endif |
2778 | signal (w->signum, SIG_DFL); |
2864 | signal (w->signum, SIG_DFL); |
|
|
2865 | } |
2779 | |
2866 | |
2780 | EV_FREQUENT_CHECK; |
2867 | EV_FREQUENT_CHECK; |
2781 | } |
2868 | } |
|
|
2869 | |
|
|
2870 | #endif |
|
|
2871 | |
|
|
2872 | #if EV_CHILD_ENABLE |
2782 | |
2873 | |
2783 | void |
2874 | void |
2784 | ev_child_start (EV_P_ ev_child *w) |
2875 | ev_child_start (EV_P_ ev_child *w) |
2785 | { |
2876 | { |
2786 | #if EV_MULTIPLICITY |
2877 | #if EV_MULTIPLICITY |
… | |
… | |
2790 | return; |
2881 | return; |
2791 | |
2882 | |
2792 | EV_FREQUENT_CHECK; |
2883 | EV_FREQUENT_CHECK; |
2793 | |
2884 | |
2794 | ev_start (EV_A_ (W)w, 1); |
2885 | ev_start (EV_A_ (W)w, 1); |
2795 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2886 | wlist_add (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2796 | |
2887 | |
2797 | EV_FREQUENT_CHECK; |
2888 | EV_FREQUENT_CHECK; |
2798 | } |
2889 | } |
2799 | |
2890 | |
2800 | void |
2891 | void |
… | |
… | |
2804 | if (expect_false (!ev_is_active (w))) |
2895 | if (expect_false (!ev_is_active (w))) |
2805 | return; |
2896 | return; |
2806 | |
2897 | |
2807 | EV_FREQUENT_CHECK; |
2898 | EV_FREQUENT_CHECK; |
2808 | |
2899 | |
2809 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2900 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2810 | ev_stop (EV_A_ (W)w); |
2901 | ev_stop (EV_A_ (W)w); |
2811 | |
2902 | |
2812 | EV_FREQUENT_CHECK; |
2903 | EV_FREQUENT_CHECK; |
2813 | } |
2904 | } |
|
|
2905 | |
|
|
2906 | #endif |
2814 | |
2907 | |
2815 | #if EV_STAT_ENABLE |
2908 | #if EV_STAT_ENABLE |
2816 | |
2909 | |
2817 | # ifdef _WIN32 |
2910 | # ifdef _WIN32 |
2818 | # undef lstat |
2911 | # undef lstat |
… | |
… | |
2824 | #define MIN_STAT_INTERVAL 0.1074891 |
2917 | #define MIN_STAT_INTERVAL 0.1074891 |
2825 | |
2918 | |
2826 | static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
2919 | static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
2827 | |
2920 | |
2828 | #if EV_USE_INOTIFY |
2921 | #if EV_USE_INOTIFY |
2829 | # define EV_INOTIFY_BUFSIZE 8192 |
2922 | |
|
|
2923 | /* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ |
|
|
2924 | # define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) |
2830 | |
2925 | |
2831 | static void noinline |
2926 | static void noinline |
2832 | infy_add (EV_P_ ev_stat *w) |
2927 | infy_add (EV_P_ ev_stat *w) |
2833 | { |
2928 | { |
2834 | w->wd = inotify_add_watch (fs_fd, w->path, IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY | IN_DONT_FOLLOW | IN_MASK_ADD); |
2929 | w->wd = inotify_add_watch (fs_fd, w->path, IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY | IN_DONT_FOLLOW | IN_MASK_ADD); |
2835 | |
2930 | |
2836 | if (w->wd < 0) |
2931 | if (w->wd >= 0) |
|
|
2932 | { |
|
|
2933 | struct statfs sfs; |
|
|
2934 | |
|
|
2935 | /* now local changes will be tracked by inotify, but remote changes won't */ |
|
|
2936 | /* unless the filesystem is known to be local, we therefore still poll */ |
|
|
2937 | /* also do poll on <2.6.25, but with normal frequency */ |
|
|
2938 | |
|
|
2939 | if (!fs_2625) |
|
|
2940 | w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL; |
|
|
2941 | else if (!statfs (w->path, &sfs) |
|
|
2942 | && (sfs.f_type == 0x1373 /* devfs */ |
|
|
2943 | || sfs.f_type == 0xEF53 /* ext2/3 */ |
|
|
2944 | || sfs.f_type == 0x3153464a /* jfs */ |
|
|
2945 | || sfs.f_type == 0x52654973 /* reiser3 */ |
|
|
2946 | || sfs.f_type == 0x01021994 /* tempfs */ |
|
|
2947 | || sfs.f_type == 0x58465342 /* xfs */)) |
|
|
2948 | w->timer.repeat = 0.; /* filesystem is local, kernel new enough */ |
|
|
2949 | else |
|
|
2950 | w->timer.repeat = w->interval ? w->interval : NFS_STAT_INTERVAL; /* remote, use reduced frequency */ |
2837 | { |
2951 | } |
|
|
2952 | else |
|
|
2953 | { |
|
|
2954 | /* can't use inotify, continue to stat */ |
2838 | w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL; |
2955 | w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL; |
2839 | ev_timer_again (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */ |
|
|
2840 | |
2956 | |
2841 | /* monitor some parent directory for speedup hints */ |
2957 | /* if path is not there, monitor some parent directory for speedup hints */ |
2842 | /* note that exceeding the hardcoded path limit is not a correctness issue, */ |
2958 | /* note that exceeding the hardcoded path limit is not a correctness issue, */ |
2843 | /* but an efficiency issue only */ |
2959 | /* but an efficiency issue only */ |
2844 | if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) |
2960 | if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) |
2845 | { |
2961 | { |
2846 | char path [4096]; |
2962 | char path [4096]; |
… | |
… | |
2862 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2978 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2863 | } |
2979 | } |
2864 | } |
2980 | } |
2865 | |
2981 | |
2866 | if (w->wd >= 0) |
2982 | if (w->wd >= 0) |
2867 | { |
|
|
2868 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2983 | wlist_add (&fs_hash [w->wd & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2869 | |
2984 | |
2870 | /* now local changes will be tracked by inotify, but remote changes won't */ |
2985 | /* now re-arm timer, if required */ |
2871 | /* unless the filesystem it known to be local, we therefore still poll */ |
2986 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2872 | /* also do poll on <2.6.25, but with normal frequency */ |
|
|
2873 | struct statfs sfs; |
|
|
2874 | |
|
|
2875 | if (fs_2625 && !statfs (w->path, &sfs)) |
|
|
2876 | if (sfs.f_type == 0x1373 /* devfs */ |
|
|
2877 | || sfs.f_type == 0xEF53 /* ext2/3 */ |
|
|
2878 | || sfs.f_type == 0x3153464a /* jfs */ |
|
|
2879 | || sfs.f_type == 0x52654973 /* reiser3 */ |
|
|
2880 | || sfs.f_type == 0x01021994 /* tempfs */ |
|
|
2881 | || sfs.f_type == 0x58465342 /* xfs */) |
|
|
2882 | return; |
|
|
2883 | |
|
|
2884 | w->timer.repeat = w->interval ? w->interval : fs_2625 ? NFS_STAT_INTERVAL : DEF_STAT_INTERVAL; |
|
|
2885 | ev_timer_again (EV_A_ &w->timer); |
2987 | ev_timer_again (EV_A_ &w->timer); |
2886 | } |
2988 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
2887 | } |
2989 | } |
2888 | |
2990 | |
2889 | static void noinline |
2991 | static void noinline |
2890 | infy_del (EV_P_ ev_stat *w) |
2992 | infy_del (EV_P_ ev_stat *w) |
2891 | { |
2993 | { |
… | |
… | |
2894 | |
2996 | |
2895 | if (wd < 0) |
2997 | if (wd < 0) |
2896 | return; |
2998 | return; |
2897 | |
2999 | |
2898 | w->wd = -2; |
3000 | w->wd = -2; |
2899 | slot = wd & (EV_INOTIFY_HASHSIZE - 1); |
3001 | slot = wd & ((EV_INOTIFY_HASHSIZE) - 1); |
2900 | wlist_del (&fs_hash [slot].head, (WL)w); |
3002 | wlist_del (&fs_hash [slot].head, (WL)w); |
2901 | |
3003 | |
2902 | /* remove this watcher, if others are watching it, they will rearm */ |
3004 | /* remove this watcher, if others are watching it, they will rearm */ |
2903 | inotify_rm_watch (fs_fd, wd); |
3005 | inotify_rm_watch (fs_fd, wd); |
2904 | } |
3006 | } |
… | |
… | |
2906 | static void noinline |
3008 | static void noinline |
2907 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
3009 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
2908 | { |
3010 | { |
2909 | if (slot < 0) |
3011 | if (slot < 0) |
2910 | /* overflow, need to check for all hash slots */ |
3012 | /* overflow, need to check for all hash slots */ |
2911 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3013 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
2912 | infy_wd (EV_A_ slot, wd, ev); |
3014 | infy_wd (EV_A_ slot, wd, ev); |
2913 | else |
3015 | else |
2914 | { |
3016 | { |
2915 | WL w_; |
3017 | WL w_; |
2916 | |
3018 | |
2917 | for (w_ = fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head; w_; ) |
3019 | for (w_ = fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head; w_; ) |
2918 | { |
3020 | { |
2919 | ev_stat *w = (ev_stat *)w_; |
3021 | ev_stat *w = (ev_stat *)w_; |
2920 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
3022 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
2921 | |
3023 | |
2922 | if (w->wd == wd || wd == -1) |
3024 | if (w->wd == wd || wd == -1) |
2923 | { |
3025 | { |
2924 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
3026 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
2925 | { |
3027 | { |
2926 | wlist_del (&fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
3028 | wlist_del (&fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2927 | w->wd = -1; |
3029 | w->wd = -1; |
2928 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3030 | infy_add (EV_A_ w); /* re-add, no matter what */ |
2929 | } |
3031 | } |
2930 | |
3032 | |
2931 | stat_timer_cb (EV_A_ &w->timer, 0); |
3033 | stat_timer_cb (EV_A_ &w->timer, 0); |
… | |
… | |
2936 | |
3038 | |
2937 | static void |
3039 | static void |
2938 | infy_cb (EV_P_ ev_io *w, int revents) |
3040 | infy_cb (EV_P_ ev_io *w, int revents) |
2939 | { |
3041 | { |
2940 | char buf [EV_INOTIFY_BUFSIZE]; |
3042 | char buf [EV_INOTIFY_BUFSIZE]; |
2941 | struct inotify_event *ev = (struct inotify_event *)buf; |
|
|
2942 | int ofs; |
3043 | int ofs; |
2943 | int len = read (fs_fd, buf, sizeof (buf)); |
3044 | int len = read (fs_fd, buf, sizeof (buf)); |
2944 | |
3045 | |
2945 | for (ofs = 0; ofs < len; ofs += sizeof (struct inotify_event) + ev->len) |
3046 | for (ofs = 0; ofs < len; ) |
|
|
3047 | { |
|
|
3048 | struct inotify_event *ev = (struct inotify_event *)(buf + ofs); |
2946 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
3049 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
|
|
3050 | ofs += sizeof (struct inotify_event) + ev->len; |
|
|
3051 | } |
|
|
3052 | } |
|
|
3053 | |
|
|
3054 | inline_size unsigned int |
|
|
3055 | ev_linux_version (void) |
|
|
3056 | { |
|
|
3057 | struct utsname buf; |
|
|
3058 | unsigned int v; |
|
|
3059 | int i; |
|
|
3060 | char *p = buf.release; |
|
|
3061 | |
|
|
3062 | if (uname (&buf)) |
|
|
3063 | return 0; |
|
|
3064 | |
|
|
3065 | for (i = 3+1; --i; ) |
|
|
3066 | { |
|
|
3067 | unsigned int c = 0; |
|
|
3068 | |
|
|
3069 | for (;;) |
|
|
3070 | { |
|
|
3071 | if (*p >= '0' && *p <= '9') |
|
|
3072 | c = c * 10 + *p++ - '0'; |
|
|
3073 | else |
|
|
3074 | { |
|
|
3075 | p += *p == '.'; |
|
|
3076 | break; |
|
|
3077 | } |
|
|
3078 | } |
|
|
3079 | |
|
|
3080 | v = (v << 8) | c; |
|
|
3081 | } |
|
|
3082 | |
|
|
3083 | return v; |
2947 | } |
3084 | } |
2948 | |
3085 | |
2949 | inline_size void |
3086 | inline_size void |
2950 | check_2625 (EV_P) |
3087 | ev_check_2625 (EV_P) |
2951 | { |
3088 | { |
2952 | /* kernels < 2.6.25 are borked |
3089 | /* kernels < 2.6.25 are borked |
2953 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
3090 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
2954 | */ |
3091 | */ |
2955 | struct utsname buf; |
3092 | if (ev_linux_version () < 0x020619) |
2956 | int major, minor, micro; |
|
|
2957 | |
|
|
2958 | if (uname (&buf)) |
|
|
2959 | return; |
3093 | return; |
2960 | |
3094 | |
2961 | if (sscanf (buf.release, "%d.%d.%d", &major, &minor, µ) != 3) |
|
|
2962 | return; |
|
|
2963 | |
|
|
2964 | if (major < 2 |
|
|
2965 | || (major == 2 && minor < 6) |
|
|
2966 | || (major == 2 && minor == 6 && micro < 25)) |
|
|
2967 | return; |
|
|
2968 | |
|
|
2969 | fs_2625 = 1; |
3095 | fs_2625 = 1; |
|
|
3096 | } |
|
|
3097 | |
|
|
3098 | inline_size int |
|
|
3099 | infy_newfd (void) |
|
|
3100 | { |
|
|
3101 | #if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) |
|
|
3102 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
|
|
3103 | if (fd >= 0) |
|
|
3104 | return fd; |
|
|
3105 | #endif |
|
|
3106 | return inotify_init (); |
2970 | } |
3107 | } |
2971 | |
3108 | |
2972 | inline_size void |
3109 | inline_size void |
2973 | infy_init (EV_P) |
3110 | infy_init (EV_P) |
2974 | { |
3111 | { |
2975 | if (fs_fd != -2) |
3112 | if (fs_fd != -2) |
2976 | return; |
3113 | return; |
2977 | |
3114 | |
2978 | fs_fd = -1; |
3115 | fs_fd = -1; |
2979 | |
3116 | |
2980 | check_2625 (EV_A); |
3117 | ev_check_2625 (EV_A); |
2981 | |
3118 | |
2982 | fs_fd = inotify_init (); |
3119 | fs_fd = infy_newfd (); |
2983 | |
3120 | |
2984 | if (fs_fd >= 0) |
3121 | if (fs_fd >= 0) |
2985 | { |
3122 | { |
|
|
3123 | fd_intern (fs_fd); |
2986 | ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ); |
3124 | ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ); |
2987 | ev_set_priority (&fs_w, EV_MAXPRI); |
3125 | ev_set_priority (&fs_w, EV_MAXPRI); |
2988 | ev_io_start (EV_A_ &fs_w); |
3126 | ev_io_start (EV_A_ &fs_w); |
|
|
3127 | ev_unref (EV_A); |
2989 | } |
3128 | } |
2990 | } |
3129 | } |
2991 | |
3130 | |
2992 | inline_size void |
3131 | inline_size void |
2993 | infy_fork (EV_P) |
3132 | infy_fork (EV_P) |
… | |
… | |
2995 | int slot; |
3134 | int slot; |
2996 | |
3135 | |
2997 | if (fs_fd < 0) |
3136 | if (fs_fd < 0) |
2998 | return; |
3137 | return; |
2999 | |
3138 | |
|
|
3139 | ev_ref (EV_A); |
|
|
3140 | ev_io_stop (EV_A_ &fs_w); |
3000 | close (fs_fd); |
3141 | close (fs_fd); |
3001 | fs_fd = inotify_init (); |
3142 | fs_fd = infy_newfd (); |
3002 | |
3143 | |
|
|
3144 | if (fs_fd >= 0) |
|
|
3145 | { |
|
|
3146 | fd_intern (fs_fd); |
|
|
3147 | ev_io_set (&fs_w, fs_fd, EV_READ); |
|
|
3148 | ev_io_start (EV_A_ &fs_w); |
|
|
3149 | ev_unref (EV_A); |
|
|
3150 | } |
|
|
3151 | |
3003 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3152 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
3004 | { |
3153 | { |
3005 | WL w_ = fs_hash [slot].head; |
3154 | WL w_ = fs_hash [slot].head; |
3006 | fs_hash [slot].head = 0; |
3155 | fs_hash [slot].head = 0; |
3007 | |
3156 | |
3008 | while (w_) |
3157 | while (w_) |
… | |
… | |
3013 | w->wd = -1; |
3162 | w->wd = -1; |
3014 | |
3163 | |
3015 | if (fs_fd >= 0) |
3164 | if (fs_fd >= 0) |
3016 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3165 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3017 | else |
3166 | else |
|
|
3167 | { |
|
|
3168 | w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL; |
|
|
3169 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
3018 | ev_timer_again (EV_A_ &w->timer); |
3170 | ev_timer_again (EV_A_ &w->timer); |
|
|
3171 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
|
|
3172 | } |
3019 | } |
3173 | } |
3020 | } |
3174 | } |
3021 | } |
3175 | } |
3022 | |
3176 | |
3023 | #endif |
3177 | #endif |
… | |
… | |
3040 | static void noinline |
3194 | static void noinline |
3041 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
3195 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
3042 | { |
3196 | { |
3043 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
3197 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
3044 | |
3198 | |
3045 | /* we copy this here each the time so that */ |
3199 | ev_statdata prev = w->attr; |
3046 | /* prev has the old value when the callback gets invoked */ |
|
|
3047 | w->prev = w->attr; |
|
|
3048 | ev_stat_stat (EV_A_ w); |
3200 | ev_stat_stat (EV_A_ w); |
3049 | |
3201 | |
3050 | /* memcmp doesn't work on netbsd, they.... do stuff to their struct stat */ |
3202 | /* memcmp doesn't work on netbsd, they.... do stuff to their struct stat */ |
3051 | if ( |
3203 | if ( |
3052 | w->prev.st_dev != w->attr.st_dev |
3204 | prev.st_dev != w->attr.st_dev |
3053 | || w->prev.st_ino != w->attr.st_ino |
3205 | || prev.st_ino != w->attr.st_ino |
3054 | || w->prev.st_mode != w->attr.st_mode |
3206 | || prev.st_mode != w->attr.st_mode |
3055 | || w->prev.st_nlink != w->attr.st_nlink |
3207 | || prev.st_nlink != w->attr.st_nlink |
3056 | || w->prev.st_uid != w->attr.st_uid |
3208 | || prev.st_uid != w->attr.st_uid |
3057 | || w->prev.st_gid != w->attr.st_gid |
3209 | || prev.st_gid != w->attr.st_gid |
3058 | || w->prev.st_rdev != w->attr.st_rdev |
3210 | || prev.st_rdev != w->attr.st_rdev |
3059 | || w->prev.st_size != w->attr.st_size |
3211 | || prev.st_size != w->attr.st_size |
3060 | || w->prev.st_atime != w->attr.st_atime |
3212 | || prev.st_atime != w->attr.st_atime |
3061 | || w->prev.st_mtime != w->attr.st_mtime |
3213 | || prev.st_mtime != w->attr.st_mtime |
3062 | || w->prev.st_ctime != w->attr.st_ctime |
3214 | || prev.st_ctime != w->attr.st_ctime |
3063 | ) { |
3215 | ) { |
|
|
3216 | /* we only update w->prev on actual differences */ |
|
|
3217 | /* in case we test more often than invoke the callback, */ |
|
|
3218 | /* to ensure that prev is always different to attr */ |
|
|
3219 | w->prev = prev; |
|
|
3220 | |
3064 | #if EV_USE_INOTIFY |
3221 | #if EV_USE_INOTIFY |
3065 | if (fs_fd >= 0) |
3222 | if (fs_fd >= 0) |
3066 | { |
3223 | { |
3067 | infy_del (EV_A_ w); |
3224 | infy_del (EV_A_ w); |
3068 | infy_add (EV_A_ w); |
3225 | infy_add (EV_A_ w); |
… | |
… | |
3093 | |
3250 | |
3094 | if (fs_fd >= 0) |
3251 | if (fs_fd >= 0) |
3095 | infy_add (EV_A_ w); |
3252 | infy_add (EV_A_ w); |
3096 | else |
3253 | else |
3097 | #endif |
3254 | #endif |
|
|
3255 | { |
3098 | ev_timer_again (EV_A_ &w->timer); |
3256 | ev_timer_again (EV_A_ &w->timer); |
|
|
3257 | ev_unref (EV_A); |
|
|
3258 | } |
3099 | |
3259 | |
3100 | ev_start (EV_A_ (W)w, 1); |
3260 | ev_start (EV_A_ (W)w, 1); |
3101 | |
3261 | |
3102 | EV_FREQUENT_CHECK; |
3262 | EV_FREQUENT_CHECK; |
3103 | } |
3263 | } |
… | |
… | |
3112 | EV_FREQUENT_CHECK; |
3272 | EV_FREQUENT_CHECK; |
3113 | |
3273 | |
3114 | #if EV_USE_INOTIFY |
3274 | #if EV_USE_INOTIFY |
3115 | infy_del (EV_A_ w); |
3275 | infy_del (EV_A_ w); |
3116 | #endif |
3276 | #endif |
|
|
3277 | |
|
|
3278 | if (ev_is_active (&w->timer)) |
|
|
3279 | { |
|
|
3280 | ev_ref (EV_A); |
3117 | ev_timer_stop (EV_A_ &w->timer); |
3281 | ev_timer_stop (EV_A_ &w->timer); |
|
|
3282 | } |
3118 | |
3283 | |
3119 | ev_stop (EV_A_ (W)w); |
3284 | ev_stop (EV_A_ (W)w); |
3120 | |
3285 | |
3121 | EV_FREQUENT_CHECK; |
3286 | EV_FREQUENT_CHECK; |
3122 | } |
3287 | } |
… | |
… | |
3167 | |
3332 | |
3168 | EV_FREQUENT_CHECK; |
3333 | EV_FREQUENT_CHECK; |
3169 | } |
3334 | } |
3170 | #endif |
3335 | #endif |
3171 | |
3336 | |
|
|
3337 | #if EV_PREPARE_ENABLE |
3172 | void |
3338 | void |
3173 | ev_prepare_start (EV_P_ ev_prepare *w) |
3339 | ev_prepare_start (EV_P_ ev_prepare *w) |
3174 | { |
3340 | { |
3175 | if (expect_false (ev_is_active (w))) |
3341 | if (expect_false (ev_is_active (w))) |
3176 | return; |
3342 | return; |
… | |
… | |
3202 | |
3368 | |
3203 | ev_stop (EV_A_ (W)w); |
3369 | ev_stop (EV_A_ (W)w); |
3204 | |
3370 | |
3205 | EV_FREQUENT_CHECK; |
3371 | EV_FREQUENT_CHECK; |
3206 | } |
3372 | } |
|
|
3373 | #endif |
3207 | |
3374 | |
|
|
3375 | #if EV_CHECK_ENABLE |
3208 | void |
3376 | void |
3209 | ev_check_start (EV_P_ ev_check *w) |
3377 | ev_check_start (EV_P_ ev_check *w) |
3210 | { |
3378 | { |
3211 | if (expect_false (ev_is_active (w))) |
3379 | if (expect_false (ev_is_active (w))) |
3212 | return; |
3380 | return; |
… | |
… | |
3238 | |
3406 | |
3239 | ev_stop (EV_A_ (W)w); |
3407 | ev_stop (EV_A_ (W)w); |
3240 | |
3408 | |
3241 | EV_FREQUENT_CHECK; |
3409 | EV_FREQUENT_CHECK; |
3242 | } |
3410 | } |
|
|
3411 | #endif |
3243 | |
3412 | |
3244 | #if EV_EMBED_ENABLE |
3413 | #if EV_EMBED_ENABLE |
3245 | void noinline |
3414 | void noinline |
3246 | ev_embed_sweep (EV_P_ ev_embed *w) |
3415 | ev_embed_sweep (EV_P_ ev_embed *w) |
3247 | { |
3416 | { |
… | |
… | |
3263 | embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents) |
3432 | embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents) |
3264 | { |
3433 | { |
3265 | ev_embed *w = (ev_embed *)(((char *)prepare) - offsetof (ev_embed, prepare)); |
3434 | ev_embed *w = (ev_embed *)(((char *)prepare) - offsetof (ev_embed, prepare)); |
3266 | |
3435 | |
3267 | { |
3436 | { |
3268 | struct ev_loop *loop = w->other; |
3437 | EV_P = w->other; |
3269 | |
3438 | |
3270 | while (fdchangecnt) |
3439 | while (fdchangecnt) |
3271 | { |
3440 | { |
3272 | fd_reify (EV_A); |
3441 | fd_reify (EV_A); |
3273 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
3442 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
… | |
… | |
3281 | ev_embed *w = (ev_embed *)(((char *)fork_w) - offsetof (ev_embed, fork)); |
3450 | ev_embed *w = (ev_embed *)(((char *)fork_w) - offsetof (ev_embed, fork)); |
3282 | |
3451 | |
3283 | ev_embed_stop (EV_A_ w); |
3452 | ev_embed_stop (EV_A_ w); |
3284 | |
3453 | |
3285 | { |
3454 | { |
3286 | struct ev_loop *loop = w->other; |
3455 | EV_P = w->other; |
3287 | |
3456 | |
3288 | ev_loop_fork (EV_A); |
3457 | ev_loop_fork (EV_A); |
3289 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
3458 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
3290 | } |
3459 | } |
3291 | |
3460 | |
… | |
… | |
3305 | { |
3474 | { |
3306 | if (expect_false (ev_is_active (w))) |
3475 | if (expect_false (ev_is_active (w))) |
3307 | return; |
3476 | return; |
3308 | |
3477 | |
3309 | { |
3478 | { |
3310 | struct ev_loop *loop = w->other; |
3479 | EV_P = w->other; |
3311 | assert (("libev: loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
3480 | assert (("libev: loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
3312 | ev_io_init (&w->io, embed_io_cb, backend_fd, EV_READ); |
3481 | ev_io_init (&w->io, embed_io_cb, backend_fd, EV_READ); |
3313 | } |
3482 | } |
3314 | |
3483 | |
3315 | EV_FREQUENT_CHECK; |
3484 | EV_FREQUENT_CHECK; |
… | |
… | |
3342 | |
3511 | |
3343 | ev_io_stop (EV_A_ &w->io); |
3512 | ev_io_stop (EV_A_ &w->io); |
3344 | ev_prepare_stop (EV_A_ &w->prepare); |
3513 | ev_prepare_stop (EV_A_ &w->prepare); |
3345 | ev_fork_stop (EV_A_ &w->fork); |
3514 | ev_fork_stop (EV_A_ &w->fork); |
3346 | |
3515 | |
|
|
3516 | ev_stop (EV_A_ (W)w); |
|
|
3517 | |
3347 | EV_FREQUENT_CHECK; |
3518 | EV_FREQUENT_CHECK; |
3348 | } |
3519 | } |
3349 | #endif |
3520 | #endif |
3350 | |
3521 | |
3351 | #if EV_FORK_ENABLE |
3522 | #if EV_FORK_ENABLE |
… | |
… | |
3427 | |
3598 | |
3428 | void |
3599 | void |
3429 | ev_async_send (EV_P_ ev_async *w) |
3600 | ev_async_send (EV_P_ ev_async *w) |
3430 | { |
3601 | { |
3431 | w->sent = 1; |
3602 | w->sent = 1; |
3432 | evpipe_write (EV_A_ &gotasync); |
3603 | evpipe_write (EV_A_ &async_pending); |
3433 | } |
3604 | } |
3434 | #endif |
3605 | #endif |
3435 | |
3606 | |
3436 | /*****************************************************************************/ |
3607 | /*****************************************************************************/ |
3437 | |
3608 | |
… | |
… | |
3477 | { |
3648 | { |
3478 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3649 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3479 | |
3650 | |
3480 | if (expect_false (!once)) |
3651 | if (expect_false (!once)) |
3481 | { |
3652 | { |
3482 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
3653 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
3483 | return; |
3654 | return; |
3484 | } |
3655 | } |
3485 | |
3656 | |
3486 | once->cb = cb; |
3657 | once->cb = cb; |
3487 | once->arg = arg; |
3658 | once->arg = arg; |
… | |
… | |
3574 | if (types & EV_ASYNC) |
3745 | if (types & EV_ASYNC) |
3575 | for (i = asynccnt; i--; ) |
3746 | for (i = asynccnt; i--; ) |
3576 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3747 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3577 | #endif |
3748 | #endif |
3578 | |
3749 | |
|
|
3750 | #if EV_PREPARE_ENABLE |
3579 | if (types & EV_PREPARE) |
3751 | if (types & EV_PREPARE) |
3580 | for (i = preparecnt; i--; ) |
3752 | for (i = preparecnt; i--; ) |
3581 | #if EV_EMBED_ENABLE |
3753 | # if EV_EMBED_ENABLE |
3582 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3754 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3583 | #endif |
3755 | # endif |
3584 | cb (EV_A_ EV_PREPARE, prepares [i]); |
3756 | cb (EV_A_ EV_PREPARE, prepares [i]); |
|
|
3757 | #endif |
3585 | |
3758 | |
|
|
3759 | #if EV_CHECK_ENABLE |
3586 | if (types & EV_CHECK) |
3760 | if (types & EV_CHECK) |
3587 | for (i = checkcnt; i--; ) |
3761 | for (i = checkcnt; i--; ) |
3588 | cb (EV_A_ EV_CHECK, checks [i]); |
3762 | cb (EV_A_ EV_CHECK, checks [i]); |
|
|
3763 | #endif |
3589 | |
3764 | |
|
|
3765 | #if EV_SIGNAL_ENABLE |
3590 | if (types & EV_SIGNAL) |
3766 | if (types & EV_SIGNAL) |
3591 | for (i = 0; i < signalmax; ++i) |
3767 | for (i = 0; i < EV_NSIG - 1; ++i) |
3592 | for (wl = signals [i].head; wl; ) |
3768 | for (wl = signals [i].head; wl; ) |
3593 | { |
3769 | { |
3594 | wn = wl->next; |
3770 | wn = wl->next; |
3595 | cb (EV_A_ EV_SIGNAL, wl); |
3771 | cb (EV_A_ EV_SIGNAL, wl); |
3596 | wl = wn; |
3772 | wl = wn; |
3597 | } |
3773 | } |
|
|
3774 | #endif |
3598 | |
3775 | |
|
|
3776 | #if EV_CHILD_ENABLE |
3599 | if (types & EV_CHILD) |
3777 | if (types & EV_CHILD) |
3600 | for (i = EV_PID_HASHSIZE; i--; ) |
3778 | for (i = (EV_PID_HASHSIZE); i--; ) |
3601 | for (wl = childs [i]; wl; ) |
3779 | for (wl = childs [i]; wl; ) |
3602 | { |
3780 | { |
3603 | wn = wl->next; |
3781 | wn = wl->next; |
3604 | cb (EV_A_ EV_CHILD, wl); |
3782 | cb (EV_A_ EV_CHILD, wl); |
3605 | wl = wn; |
3783 | wl = wn; |
3606 | } |
3784 | } |
|
|
3785 | #endif |
3607 | /* EV_STAT 0x00001000 /* stat data changed */ |
3786 | /* EV_STAT 0x00001000 /* stat data changed */ |
3608 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3787 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3609 | } |
3788 | } |
3610 | #endif |
3789 | #endif |
3611 | |
3790 | |