ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.337 by root, Wed Mar 10 09:18:24 2010 UTC vs.
Revision 1.344 by root, Fri Jul 9 20:55:14 2010 UTC

77# ifndef EV_USE_REALTIME 77# ifndef EV_USE_REALTIME
78# define EV_USE_REALTIME 0 78# define EV_USE_REALTIME 0
79# endif 79# endif
80# endif 80# endif
81 81
82# if HAVE_NANOSLEEP
82# ifndef EV_USE_NANOSLEEP 83# ifndef EV_USE_NANOSLEEP
83# if HAVE_NANOSLEEP
84# define EV_USE_NANOSLEEP 1 84# define EV_USE_NANOSLEEP EV_FEATURE_OS
85# endif
85# else 86# else
87# undef EV_USE_NANOSLEEP
86# define EV_USE_NANOSLEEP 0 88# define EV_USE_NANOSLEEP 0
89# endif
90
91# if HAVE_SELECT && HAVE_SYS_SELECT_H
92# ifndef EV_USE_SELECT
93# define EV_USE_SELECT EV_FEATURE_BACKENDS
87# endif 94# endif
95# else
96# undef EV_USE_SELECT
97# define EV_USE_SELECT 0
88# endif 98# endif
89 99
100# if HAVE_POLL && HAVE_POLL_H
90# ifndef EV_USE_SELECT 101# ifndef EV_USE_POLL
91# if HAVE_SELECT && HAVE_SYS_SELECT_H 102# define EV_USE_POLL EV_FEATURE_BACKENDS
92# define EV_USE_SELECT 1
93# else
94# define EV_USE_SELECT 0
95# endif 103# endif
96# endif
97
98# ifndef EV_USE_POLL
99# if HAVE_POLL && HAVE_POLL_H
100# define EV_USE_POLL 1
101# else 104# else
105# undef EV_USE_POLL
102# define EV_USE_POLL 0 106# define EV_USE_POLL 0
103# endif
104# endif 107# endif
105 108
106# ifndef EV_USE_EPOLL
107# if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H 109# if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H
108# define EV_USE_EPOLL 1 110# ifndef EV_USE_EPOLL
109# else 111# define EV_USE_EPOLL EV_FEATURE_BACKENDS
110# define EV_USE_EPOLL 0
111# endif 112# endif
113# else
114# undef EV_USE_EPOLL
115# define EV_USE_EPOLL 0
112# endif 116# endif
113 117
114# ifndef EV_USE_KQUEUE
115# if HAVE_KQUEUE && HAVE_SYS_EVENT_H 118# if HAVE_KQUEUE && HAVE_SYS_EVENT_H
116# define EV_USE_KQUEUE 1 119# ifndef EV_USE_KQUEUE
117# else 120# define EV_USE_KQUEUE EV_FEATURE_BACKENDS
118# define EV_USE_KQUEUE 0
119# endif 121# endif
122# else
123# undef EV_USE_KQUEUE
124# define EV_USE_KQUEUE 0
120# endif 125# endif
121 126
122# ifndef EV_USE_PORT
123# if HAVE_PORT_H && HAVE_PORT_CREATE 127# if HAVE_PORT_H && HAVE_PORT_CREATE
124# define EV_USE_PORT 1 128# ifndef EV_USE_PORT
125# else 129# define EV_USE_PORT EV_FEATURE_BACKENDS
126# define EV_USE_PORT 0
127# endif 130# endif
131# else
132# undef EV_USE_PORT
133# define EV_USE_PORT 0
128# endif 134# endif
129 135
130# ifndef EV_USE_INOTIFY
131# if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H 136# if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H
132# define EV_USE_INOTIFY 1 137# ifndef EV_USE_INOTIFY
133# else
134# define EV_USE_INOTIFY 0 138# define EV_USE_INOTIFY EV_FEATURE_OS
135# endif 139# endif
140# else
141# undef EV_USE_INOTIFY
142# define EV_USE_INOTIFY 0
136# endif 143# endif
137 144
138# ifndef EV_USE_SIGNALFD
139# if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H 145# if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H
140# define EV_USE_SIGNALFD 1 146# ifndef EV_USE_SIGNALFD
141# else
142# define EV_USE_SIGNALFD 0 147# define EV_USE_SIGNALFD EV_FEATURE_OS
143# endif 148# endif
149# else
150# undef EV_USE_SIGNALFD
151# define EV_USE_SIGNALFD 0
144# endif 152# endif
145 153
154# if HAVE_EVENTFD
146# ifndef EV_USE_EVENTFD 155# ifndef EV_USE_EVENTFD
147# if HAVE_EVENTFD
148# define EV_USE_EVENTFD 1 156# define EV_USE_EVENTFD EV_FEATURE_OS
149# else
150# define EV_USE_EVENTFD 0
151# endif 157# endif
158# else
159# undef EV_USE_EVENTFD
160# define EV_USE_EVENTFD 0
152# endif 161# endif
153 162
154#endif 163#endif
155 164
156#include <math.h> 165#include <math.h>
186# ifndef EV_SELECT_IS_WINSOCKET 195# ifndef EV_SELECT_IS_WINSOCKET
187# define EV_SELECT_IS_WINSOCKET 1 196# define EV_SELECT_IS_WINSOCKET 1
188# endif 197# endif
189# undef EV_AVOID_STDIO 198# undef EV_AVOID_STDIO
190#endif 199#endif
200
201/* OS X, in its infinite idiocy, actually HARDCODES
202 * a limit of 1024 into their select. Where people have brains,
203 * OS X engineers apparently have a vacuum. Or maybe they were
204 * ordered to have a vacuum, or they do anything for money.
205 * This might help. Or not.
206 */
207#define _DARWIN_UNLIMITED_SELECT 1
191 208
192/* this block tries to deduce configuration from header-defined symbols and defaults */ 209/* this block tries to deduce configuration from header-defined symbols and defaults */
193 210
194/* try to deduce the maximum number of signals on this platform */ 211/* try to deduce the maximum number of signals on this platform */
195#if defined (EV_NSIG) 212#if defined (EV_NSIG)
219# define EV_NSIG 65 236# define EV_NSIG 65
220#endif 237#endif
221 238
222#ifndef EV_USE_CLOCK_SYSCALL 239#ifndef EV_USE_CLOCK_SYSCALL
223# if __linux && __GLIBC__ >= 2 240# if __linux && __GLIBC__ >= 2
224# define EV_USE_CLOCK_SYSCALL 1 241# define EV_USE_CLOCK_SYSCALL EV_FEATURE_OS
225# else 242# else
226# define EV_USE_CLOCK_SYSCALL 0 243# define EV_USE_CLOCK_SYSCALL 0
227# endif 244# endif
228#endif 245#endif
229 246
230#ifndef EV_USE_MONOTONIC 247#ifndef EV_USE_MONOTONIC
231# if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 248# if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0
232# define EV_USE_MONOTONIC 1 249# define EV_USE_MONOTONIC EV_FEATURE_OS
233# else 250# else
234# define EV_USE_MONOTONIC 0 251# define EV_USE_MONOTONIC 0
235# endif 252# endif
236#endif 253#endif
237 254
239# define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL 256# define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL
240#endif 257#endif
241 258
242#ifndef EV_USE_NANOSLEEP 259#ifndef EV_USE_NANOSLEEP
243# if _POSIX_C_SOURCE >= 199309L 260# if _POSIX_C_SOURCE >= 199309L
244# define EV_USE_NANOSLEEP 1 261# define EV_USE_NANOSLEEP EV_FEATURE_OS
245# else 262# else
246# define EV_USE_NANOSLEEP 0 263# define EV_USE_NANOSLEEP 0
247# endif 264# endif
248#endif 265#endif
249 266
250#ifndef EV_USE_SELECT 267#ifndef EV_USE_SELECT
251# define EV_USE_SELECT 1 268# define EV_USE_SELECT EV_FEATURE_BACKENDS
252#endif 269#endif
253 270
254#ifndef EV_USE_POLL 271#ifndef EV_USE_POLL
255# ifdef _WIN32 272# ifdef _WIN32
256# define EV_USE_POLL 0 273# define EV_USE_POLL 0
257# else 274# else
258# define EV_USE_POLL 1 275# define EV_USE_POLL EV_FEATURE_BACKENDS
259# endif 276# endif
260#endif 277#endif
261 278
262#ifndef EV_USE_EPOLL 279#ifndef EV_USE_EPOLL
263# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) 280# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
264# define EV_USE_EPOLL 1 281# define EV_USE_EPOLL EV_FEATURE_BACKENDS
265# else 282# else
266# define EV_USE_EPOLL 0 283# define EV_USE_EPOLL 0
267# endif 284# endif
268#endif 285#endif
269 286
275# define EV_USE_PORT 0 292# define EV_USE_PORT 0
276#endif 293#endif
277 294
278#ifndef EV_USE_INOTIFY 295#ifndef EV_USE_INOTIFY
279# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) 296# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
280# define EV_USE_INOTIFY 1 297# define EV_USE_INOTIFY EV_FEATURE_OS
281# else 298# else
282# define EV_USE_INOTIFY 0 299# define EV_USE_INOTIFY 0
283# endif 300# endif
284#endif 301#endif
285 302
286#ifndef EV_PID_HASHSIZE 303#ifndef EV_PID_HASHSIZE
287# if EV_MINIMAL 304# define EV_PID_HASHSIZE EV_FEATURE_DATA ? 16 : 1
288# define EV_PID_HASHSIZE 1
289# else
290# define EV_PID_HASHSIZE 16
291# endif
292#endif 305#endif
293 306
294#ifndef EV_INOTIFY_HASHSIZE 307#ifndef EV_INOTIFY_HASHSIZE
295# if EV_MINIMAL 308# define EV_INOTIFY_HASHSIZE EV_FEATURE_DATA ? 16 : 1
296# define EV_INOTIFY_HASHSIZE 1
297# else
298# define EV_INOTIFY_HASHSIZE 16
299# endif
300#endif 309#endif
301 310
302#ifndef EV_USE_EVENTFD 311#ifndef EV_USE_EVENTFD
303# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) 312# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7))
304# define EV_USE_EVENTFD 1 313# define EV_USE_EVENTFD EV_FEATURE_OS
305# else 314# else
306# define EV_USE_EVENTFD 0 315# define EV_USE_EVENTFD 0
307# endif 316# endif
308#endif 317#endif
309 318
310#ifndef EV_USE_SIGNALFD 319#ifndef EV_USE_SIGNALFD
311# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) 320# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7))
312# define EV_USE_SIGNALFD 1 321# define EV_USE_SIGNALFD EV_FEATURE_OS
313# else 322# else
314# define EV_USE_SIGNALFD 0 323# define EV_USE_SIGNALFD 0
315# endif 324# endif
316#endif 325#endif
317 326
320# define EV_USE_4HEAP 1 329# define EV_USE_4HEAP 1
321# define EV_HEAP_CACHE_AT 1 330# define EV_HEAP_CACHE_AT 1
322#endif 331#endif
323 332
324#ifndef EV_VERIFY 333#ifndef EV_VERIFY
325# define EV_VERIFY !EV_MINIMAL 334# define EV_VERIFY (EV_FEATURE_API ? 1 : 0)
326#endif 335#endif
327 336
328#ifndef EV_USE_4HEAP 337#ifndef EV_USE_4HEAP
329# define EV_USE_4HEAP !EV_MINIMAL 338# define EV_USE_4HEAP EV_FEATURE_DATA
330#endif 339#endif
331 340
332#ifndef EV_HEAP_CACHE_AT 341#ifndef EV_HEAP_CACHE_AT
333# define EV_HEAP_CACHE_AT !EV_MINIMAL 342# define EV_HEAP_CACHE_AT EV_FEATURE_DATA
334#endif 343#endif
335 344
336/* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ 345/* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */
337/* which makes programs even slower. might work on other unices, too. */ 346/* which makes programs even slower. might work on other unices, too. */
338#if EV_USE_CLOCK_SYSCALL 347#if EV_USE_CLOCK_SYSCALL
443 452
444 453
445/**/ 454/**/
446 455
447#if EV_VERIFY >= 3 456#if EV_VERIFY >= 3
448# define EV_FREQUENT_CHECK ev_loop_verify (EV_A) 457# define EV_FREQUENT_CHECK ev_verify (EV_A)
449#else 458#else
450# define EV_FREQUENT_CHECK do { } while (0) 459# define EV_FREQUENT_CHECK do { } while (0)
451#endif 460#endif
452 461
453/* 462/*
476 485
477#define expect_false(expr) expect ((expr) != 0, 0) 486#define expect_false(expr) expect ((expr) != 0, 0)
478#define expect_true(expr) expect ((expr) != 0, 1) 487#define expect_true(expr) expect ((expr) != 0, 1)
479#define inline_size static inline 488#define inline_size static inline
480 489
481#if EV_MINIMAL 490#if EV_FEATURE_CODE
491# define inline_speed static inline
492#else
482# define inline_speed static noinline 493# define inline_speed static noinline
483#else
484# define inline_speed static inline
485#endif 494#endif
486 495
487#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) 496#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
488 497
489#if EV_MINPRI == EV_MAXPRI 498#if EV_MINPRI == EV_MAXPRI
696 705
697 static int ev_default_loop_ptr; 706 static int ev_default_loop_ptr;
698 707
699#endif 708#endif
700 709
701#if EV_MINIMAL < 2 710#if EV_FEATURE_API
702# define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) 711# define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A)
703# define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) 712# define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A)
704# define EV_INVOKE_PENDING invoke_cb (EV_A) 713# define EV_INVOKE_PENDING invoke_cb (EV_A)
705#else 714#else
706# define EV_RELEASE_CB (void)0 715# define EV_RELEASE_CB (void)0
1403child_reap (EV_P_ int chain, int pid, int status) 1412child_reap (EV_P_ int chain, int pid, int status)
1404{ 1413{
1405 ev_child *w; 1414 ev_child *w;
1406 int traced = WIFSTOPPED (status) || WIFCONTINUED (status); 1415 int traced = WIFSTOPPED (status) || WIFCONTINUED (status);
1407 1416
1408 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) 1417 for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next)
1409 { 1418 {
1410 if ((w->pid == pid || !w->pid) 1419 if ((w->pid == pid || !w->pid)
1411 && (!traced || (w->flags & 1))) 1420 && (!traced || (w->flags & 1)))
1412 { 1421 {
1413 ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ 1422 ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */
1438 /* make sure we are called again until all children have been reaped */ 1447 /* make sure we are called again until all children have been reaped */
1439 /* we need to do it this way so that the callback gets called before we continue */ 1448 /* we need to do it this way so that the callback gets called before we continue */
1440 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); 1449 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
1441 1450
1442 child_reap (EV_A_ pid, pid, status); 1451 child_reap (EV_A_ pid, pid, status);
1443 if (EV_PID_HASHSIZE > 1) 1452 if ((EV_PID_HASHSIZE) > 1)
1444 child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ 1453 child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */
1445} 1454}
1446 1455
1447#endif 1456#endif
1448 1457
1515#ifdef __APPLE__ 1524#ifdef __APPLE__
1516 /* only select works correctly on that "unix-certified" platform */ 1525 /* only select works correctly on that "unix-certified" platform */
1517 flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ 1526 flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */
1518 flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ 1527 flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */
1519#endif 1528#endif
1529#ifdef __FreeBSD__
1530 flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */
1531#endif
1520 1532
1521 return flags; 1533 return flags;
1522} 1534}
1523 1535
1524unsigned int 1536unsigned int
1537ev_backend (EV_P) 1549ev_backend (EV_P)
1538{ 1550{
1539 return backend; 1551 return backend;
1540} 1552}
1541 1553
1542#if EV_MINIMAL < 2 1554#if EV_FEATURE_API
1543unsigned int 1555unsigned int
1544ev_loop_count (EV_P) 1556ev_iteration (EV_P)
1545{ 1557{
1546 return loop_count; 1558 return loop_count;
1547} 1559}
1548 1560
1549unsigned int 1561unsigned int
1550ev_loop_depth (EV_P) 1562ev_depth (EV_P)
1551{ 1563{
1552 return loop_depth; 1564 return loop_depth;
1553} 1565}
1554 1566
1555void 1567void
1627 1639
1628 ev_rt_now = ev_time (); 1640 ev_rt_now = ev_time ();
1629 mn_now = get_clock (); 1641 mn_now = get_clock ();
1630 now_floor = mn_now; 1642 now_floor = mn_now;
1631 rtmn_diff = ev_rt_now - mn_now; 1643 rtmn_diff = ev_rt_now - mn_now;
1632#if EV_MINIMAL < 2 1644#if EV_FEATURE_API
1633 invoke_cb = ev_invoke_pending; 1645 invoke_cb = ev_invoke_pending;
1634#endif 1646#endif
1635 1647
1636 io_blocktime = 0.; 1648 io_blocktime = 0.;
1637 timeout_blocktime = 0.; 1649 timeout_blocktime = 0.;
1874 verify_watcher (EV_A_ ws [cnt]); 1886 verify_watcher (EV_A_ ws [cnt]);
1875 } 1887 }
1876} 1888}
1877#endif 1889#endif
1878 1890
1879#if EV_MINIMAL < 2 1891#if EV_FEATURE_API
1880void 1892void
1881ev_loop_verify (EV_P) 1893ev_verify (EV_P)
1882{ 1894{
1883#if EV_VERIFY 1895#if EV_VERIFY
1884 int i; 1896 int i;
1885 WL w; 1897 WL w;
1886 1898
1937 array_verify (EV_A_ (W *)checks, checkcnt); 1949 array_verify (EV_A_ (W *)checks, checkcnt);
1938#endif 1950#endif
1939 1951
1940# if 0 1952# if 0
1941#if EV_CHILD_ENABLE 1953#if EV_CHILD_ENABLE
1942 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) 1954 for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next)
1943 for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) 1955 for (signum = EV_NSIG; signum--; ) if (signals [signum].pending)
1944#endif 1956#endif
1945# endif 1957# endif
1946#endif 1958#endif
1947} 1959}
2104 EV_FREQUENT_CHECK; 2116 EV_FREQUENT_CHECK;
2105 feed_reverse (EV_A_ (W)w); 2117 feed_reverse (EV_A_ (W)w);
2106 } 2118 }
2107 while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); 2119 while (timercnt && ANHE_at (timers [HEAP0]) < mn_now);
2108 2120
2109 feed_reverse_done (EV_A_ EV_TIMEOUT); 2121 feed_reverse_done (EV_A_ EV_TIMER);
2110 } 2122 }
2111} 2123}
2112 2124
2113#if EV_PERIODIC_ENABLE 2125#if EV_PERIODIC_ENABLE
2114/* make periodics pending */ 2126/* make periodics pending */
2275} 2287}
2276 2288
2277void 2289void
2278ev_loop (EV_P_ int flags) 2290ev_loop (EV_P_ int flags)
2279{ 2291{
2280#if EV_MINIMAL < 2 2292#if EV_FEATURE_API
2281 ++loop_depth; 2293 ++loop_depth;
2282#endif 2294#endif
2283 2295
2284 assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); 2296 assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE));
2285 2297
2288 EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ 2300 EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */
2289 2301
2290 do 2302 do
2291 { 2303 {
2292#if EV_VERIFY >= 2 2304#if EV_VERIFY >= 2
2293 ev_loop_verify (EV_A); 2305 ev_verify (EV_A);
2294#endif 2306#endif
2295 2307
2296#ifndef _WIN32 2308#ifndef _WIN32
2297 if (expect_false (curpid)) /* penalise the forking check even more */ 2309 if (expect_false (curpid)) /* penalise the forking check even more */
2298 if (expect_false (getpid () != curpid)) 2310 if (expect_false (getpid () != curpid))
2378 waittime -= sleeptime; 2390 waittime -= sleeptime;
2379 } 2391 }
2380 } 2392 }
2381 } 2393 }
2382 2394
2383#if EV_MINIMAL < 2 2395#if EV_FEATURE_API
2384 ++loop_count; 2396 ++loop_count;
2385#endif 2397#endif
2386 assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ 2398 assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */
2387 backend_poll (EV_A_ waittime); 2399 backend_poll (EV_A_ waittime);
2388 assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ 2400 assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */
2417 )); 2429 ));
2418 2430
2419 if (loop_done == EVUNLOOP_ONE) 2431 if (loop_done == EVUNLOOP_ONE)
2420 loop_done = EVUNLOOP_CANCEL; 2432 loop_done = EVUNLOOP_CANCEL;
2421 2433
2422#if EV_MINIMAL < 2 2434#if EV_FEATURE_API
2423 --loop_depth; 2435 --loop_depth;
2424#endif 2436#endif
2425} 2437}
2426 2438
2427void 2439void
2877 return; 2889 return;
2878 2890
2879 EV_FREQUENT_CHECK; 2891 EV_FREQUENT_CHECK;
2880 2892
2881 ev_start (EV_A_ (W)w, 1); 2893 ev_start (EV_A_ (W)w, 1);
2882 wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); 2894 wlist_add (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w);
2883 2895
2884 EV_FREQUENT_CHECK; 2896 EV_FREQUENT_CHECK;
2885} 2897}
2886 2898
2887void 2899void
2891 if (expect_false (!ev_is_active (w))) 2903 if (expect_false (!ev_is_active (w)))
2892 return; 2904 return;
2893 2905
2894 EV_FREQUENT_CHECK; 2906 EV_FREQUENT_CHECK;
2895 2907
2896 wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); 2908 wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w);
2897 ev_stop (EV_A_ (W)w); 2909 ev_stop (EV_A_ (W)w);
2898 2910
2899 EV_FREQUENT_CHECK; 2911 EV_FREQUENT_CHECK;
2900} 2912}
2901 2913
2974 while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); 2986 while (w->wd < 0 && (errno == ENOENT || errno == EACCES));
2975 } 2987 }
2976 } 2988 }
2977 2989
2978 if (w->wd >= 0) 2990 if (w->wd >= 0)
2979 wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); 2991 wlist_add (&fs_hash [w->wd & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w);
2980 2992
2981 /* now re-arm timer, if required */ 2993 /* now re-arm timer, if required */
2982 if (ev_is_active (&w->timer)) ev_ref (EV_A); 2994 if (ev_is_active (&w->timer)) ev_ref (EV_A);
2983 ev_timer_again (EV_A_ &w->timer); 2995 ev_timer_again (EV_A_ &w->timer);
2984 if (ev_is_active (&w->timer)) ev_unref (EV_A); 2996 if (ev_is_active (&w->timer)) ev_unref (EV_A);
2992 3004
2993 if (wd < 0) 3005 if (wd < 0)
2994 return; 3006 return;
2995 3007
2996 w->wd = -2; 3008 w->wd = -2;
2997 slot = wd & (EV_INOTIFY_HASHSIZE - 1); 3009 slot = wd & ((EV_INOTIFY_HASHSIZE) - 1);
2998 wlist_del (&fs_hash [slot].head, (WL)w); 3010 wlist_del (&fs_hash [slot].head, (WL)w);
2999 3011
3000 /* remove this watcher, if others are watching it, they will rearm */ 3012 /* remove this watcher, if others are watching it, they will rearm */
3001 inotify_rm_watch (fs_fd, wd); 3013 inotify_rm_watch (fs_fd, wd);
3002} 3014}
3004static void noinline 3016static void noinline
3005infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) 3017infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev)
3006{ 3018{
3007 if (slot < 0) 3019 if (slot < 0)
3008 /* overflow, need to check for all hash slots */ 3020 /* overflow, need to check for all hash slots */
3009 for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) 3021 for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot)
3010 infy_wd (EV_A_ slot, wd, ev); 3022 infy_wd (EV_A_ slot, wd, ev);
3011 else 3023 else
3012 { 3024 {
3013 WL w_; 3025 WL w_;
3014 3026
3015 for (w_ = fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head; w_; ) 3027 for (w_ = fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head; w_; )
3016 { 3028 {
3017 ev_stat *w = (ev_stat *)w_; 3029 ev_stat *w = (ev_stat *)w_;
3018 w_ = w_->next; /* lets us remove this watcher and all before it */ 3030 w_ = w_->next; /* lets us remove this watcher and all before it */
3019 3031
3020 if (w->wd == wd || wd == -1) 3032 if (w->wd == wd || wd == -1)
3021 { 3033 {
3022 if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) 3034 if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF))
3023 { 3035 {
3024 wlist_del (&fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); 3036 wlist_del (&fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w);
3025 w->wd = -1; 3037 w->wd = -1;
3026 infy_add (EV_A_ w); /* re-add, no matter what */ 3038 infy_add (EV_A_ w); /* re-add, no matter what */
3027 } 3039 }
3028 3040
3029 stat_timer_cb (EV_A_ &w->timer, 0); 3041 stat_timer_cb (EV_A_ &w->timer, 0);
3143 ev_io_set (&fs_w, fs_fd, EV_READ); 3155 ev_io_set (&fs_w, fs_fd, EV_READ);
3144 ev_io_start (EV_A_ &fs_w); 3156 ev_io_start (EV_A_ &fs_w);
3145 ev_unref (EV_A); 3157 ev_unref (EV_A);
3146 } 3158 }
3147 3159
3148 for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) 3160 for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot)
3149 { 3161 {
3150 WL w_ = fs_hash [slot].head; 3162 WL w_ = fs_hash [slot].head;
3151 fs_hash [slot].head = 0; 3163 fs_hash [slot].head = 0;
3152 3164
3153 while (w_) 3165 while (w_)
3644{ 3656{
3645 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 3657 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
3646 3658
3647 if (expect_false (!once)) 3659 if (expect_false (!once))
3648 { 3660 {
3649 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); 3661 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg);
3650 return; 3662 return;
3651 } 3663 }
3652 3664
3653 once->cb = cb; 3665 once->cb = cb;
3654 once->arg = arg; 3666 once->arg = arg;
3769 } 3781 }
3770#endif 3782#endif
3771 3783
3772#if EV_CHILD_ENABLE 3784#if EV_CHILD_ENABLE
3773 if (types & EV_CHILD) 3785 if (types & EV_CHILD)
3774 for (i = EV_PID_HASHSIZE; i--; ) 3786 for (i = (EV_PID_HASHSIZE); i--; )
3775 for (wl = childs [i]; wl; ) 3787 for (wl = childs [i]; wl; )
3776 { 3788 {
3777 wn = wl->next; 3789 wn = wl->next;
3778 cb (EV_A_ EV_CHILD, wl); 3790 cb (EV_A_ EV_CHILD, wl);
3779 wl = wn; 3791 wl = wn;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines