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.343 by root, Fri Apr 2 21:03:46 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
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 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>
219# define EV_NSIG 65 228# define EV_NSIG 65
220#endif 229#endif
221 230
222#ifndef EV_USE_CLOCK_SYSCALL 231#ifndef EV_USE_CLOCK_SYSCALL
223# if __linux && __GLIBC__ >= 2 232# if __linux && __GLIBC__ >= 2
224# define EV_USE_CLOCK_SYSCALL 1 233# define EV_USE_CLOCK_SYSCALL EV_FEATURE_OS
225# else 234# else
226# define EV_USE_CLOCK_SYSCALL 0 235# define EV_USE_CLOCK_SYSCALL 0
227# endif 236# endif
228#endif 237#endif
229 238
230#ifndef EV_USE_MONOTONIC 239#ifndef EV_USE_MONOTONIC
231# if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 240# if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0
232# define EV_USE_MONOTONIC 1 241# define EV_USE_MONOTONIC EV_FEATURE_OS
233# else 242# else
234# define EV_USE_MONOTONIC 0 243# define EV_USE_MONOTONIC 0
235# endif 244# endif
236#endif 245#endif
237 246
239# define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL 248# define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL
240#endif 249#endif
241 250
242#ifndef EV_USE_NANOSLEEP 251#ifndef EV_USE_NANOSLEEP
243# if _POSIX_C_SOURCE >= 199309L 252# if _POSIX_C_SOURCE >= 199309L
244# define EV_USE_NANOSLEEP 1 253# define EV_USE_NANOSLEEP EV_FEATURE_OS
245# else 254# else
246# define EV_USE_NANOSLEEP 0 255# define EV_USE_NANOSLEEP 0
247# endif 256# endif
248#endif 257#endif
249 258
250#ifndef EV_USE_SELECT 259#ifndef EV_USE_SELECT
251# define EV_USE_SELECT 1 260# define EV_USE_SELECT EV_FEATURE_BACKENDS
252#endif 261#endif
253 262
254#ifndef EV_USE_POLL 263#ifndef EV_USE_POLL
255# ifdef _WIN32 264# ifdef _WIN32
256# define EV_USE_POLL 0 265# define EV_USE_POLL 0
257# else 266# else
258# define EV_USE_POLL 1 267# define EV_USE_POLL EV_FEATURE_BACKENDS
259# endif 268# endif
260#endif 269#endif
261 270
262#ifndef EV_USE_EPOLL 271#ifndef EV_USE_EPOLL
263# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) 272# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
264# define EV_USE_EPOLL 1 273# define EV_USE_EPOLL EV_FEATURE_BACKENDS
265# else 274# else
266# define EV_USE_EPOLL 0 275# define EV_USE_EPOLL 0
267# endif 276# endif
268#endif 277#endif
269 278
275# define EV_USE_PORT 0 284# define EV_USE_PORT 0
276#endif 285#endif
277 286
278#ifndef EV_USE_INOTIFY 287#ifndef EV_USE_INOTIFY
279# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) 288# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
280# define EV_USE_INOTIFY 1 289# define EV_USE_INOTIFY EV_FEATURE_OS
281# else 290# else
282# define EV_USE_INOTIFY 0 291# define EV_USE_INOTIFY 0
283# endif 292# endif
284#endif 293#endif
285 294
286#ifndef EV_PID_HASHSIZE 295#ifndef EV_PID_HASHSIZE
287# if EV_MINIMAL 296# 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 297#endif
293 298
294#ifndef EV_INOTIFY_HASHSIZE 299#ifndef EV_INOTIFY_HASHSIZE
295# if EV_MINIMAL 300# 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 301#endif
301 302
302#ifndef EV_USE_EVENTFD 303#ifndef EV_USE_EVENTFD
303# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) 304# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7))
304# define EV_USE_EVENTFD 1 305# define EV_USE_EVENTFD EV_FEATURE_OS
305# else 306# else
306# define EV_USE_EVENTFD 0 307# define EV_USE_EVENTFD 0
307# endif 308# endif
308#endif 309#endif
309 310
310#ifndef EV_USE_SIGNALFD 311#ifndef EV_USE_SIGNALFD
311# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) 312# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7))
312# define EV_USE_SIGNALFD 1 313# define EV_USE_SIGNALFD EV_FEATURE_OS
313# else 314# else
314# define EV_USE_SIGNALFD 0 315# define EV_USE_SIGNALFD 0
315# endif 316# endif
316#endif 317#endif
317 318
320# define EV_USE_4HEAP 1 321# define EV_USE_4HEAP 1
321# define EV_HEAP_CACHE_AT 1 322# define EV_HEAP_CACHE_AT 1
322#endif 323#endif
323 324
324#ifndef EV_VERIFY 325#ifndef EV_VERIFY
325# define EV_VERIFY !EV_MINIMAL 326# define EV_VERIFY (EV_FEATURE_API ? 1 : 0)
326#endif 327#endif
327 328
328#ifndef EV_USE_4HEAP 329#ifndef EV_USE_4HEAP
329# define EV_USE_4HEAP !EV_MINIMAL 330# define EV_USE_4HEAP EV_FEATURE_DATA
330#endif 331#endif
331 332
332#ifndef EV_HEAP_CACHE_AT 333#ifndef EV_HEAP_CACHE_AT
333# define EV_HEAP_CACHE_AT !EV_MINIMAL 334# define EV_HEAP_CACHE_AT EV_FEATURE_DATA
334#endif 335#endif
335 336
336/* 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, */
337/* which makes programs even slower. might work on other unices, too. */ 338/* which makes programs even slower. might work on other unices, too. */
338#if EV_USE_CLOCK_SYSCALL 339#if EV_USE_CLOCK_SYSCALL
443 444
444 445
445/**/ 446/**/
446 447
447#if EV_VERIFY >= 3 448#if EV_VERIFY >= 3
448# define EV_FREQUENT_CHECK ev_loop_verify (EV_A) 449# define EV_FREQUENT_CHECK ev_verify (EV_A)
449#else 450#else
450# define EV_FREQUENT_CHECK do { } while (0) 451# define EV_FREQUENT_CHECK do { } while (0)
451#endif 452#endif
452 453
453/* 454/*
476 477
477#define expect_false(expr) expect ((expr) != 0, 0) 478#define expect_false(expr) expect ((expr) != 0, 0)
478#define expect_true(expr) expect ((expr) != 0, 1) 479#define expect_true(expr) expect ((expr) != 0, 1)
479#define inline_size static inline 480#define inline_size static inline
480 481
481#if EV_MINIMAL 482#if EV_FEATURE_CODE
483# define inline_speed static inline
484#else
482# define inline_speed static noinline 485# define inline_speed static noinline
483#else
484# define inline_speed static inline
485#endif 486#endif
486 487
487#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) 488#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
488 489
489#if EV_MINPRI == EV_MAXPRI 490#if EV_MINPRI == EV_MAXPRI
696 697
697 static int ev_default_loop_ptr; 698 static int ev_default_loop_ptr;
698 699
699#endif 700#endif
700 701
701#if EV_MINIMAL < 2 702#if EV_FEATURE_API
702# 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)
703# 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)
704# define EV_INVOKE_PENDING invoke_cb (EV_A) 705# define EV_INVOKE_PENDING invoke_cb (EV_A)
705#else 706#else
706# define EV_RELEASE_CB (void)0 707# define EV_RELEASE_CB (void)0
1403child_reap (EV_P_ int chain, int pid, int status) 1404child_reap (EV_P_ int chain, int pid, int status)
1404{ 1405{
1405 ev_child *w; 1406 ev_child *w;
1406 int traced = WIFSTOPPED (status) || WIFCONTINUED (status); 1407 int traced = WIFSTOPPED (status) || WIFCONTINUED (status);
1407 1408
1408 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)
1409 { 1410 {
1410 if ((w->pid == pid || !w->pid) 1411 if ((w->pid == pid || !w->pid)
1411 && (!traced || (w->flags & 1))) 1412 && (!traced || (w->flags & 1)))
1412 { 1413 {
1413 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 */
1438 /* 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 */
1439 /* 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 */
1440 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); 1441 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
1441 1442
1442 child_reap (EV_A_ pid, pid, status); 1443 child_reap (EV_A_ pid, pid, status);
1443 if (EV_PID_HASHSIZE > 1) 1444 if ((EV_PID_HASHSIZE) > 1)
1444 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 */
1445} 1446}
1446 1447
1447#endif 1448#endif
1448 1449
1515#ifdef __APPLE__ 1516#ifdef __APPLE__
1516 /* only select works correctly on that "unix-certified" platform */ 1517 /* only select works correctly on that "unix-certified" platform */
1517 flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ 1518 flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */
1518 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 */
1519#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
1520 1524
1521 return flags; 1525 return flags;
1522} 1526}
1523 1527
1524unsigned int 1528unsigned int
1537ev_backend (EV_P) 1541ev_backend (EV_P)
1538{ 1542{
1539 return backend; 1543 return backend;
1540} 1544}
1541 1545
1542#if EV_MINIMAL < 2 1546#if EV_FEATURE_API
1543unsigned int 1547unsigned int
1544ev_loop_count (EV_P) 1548ev_iteration (EV_P)
1545{ 1549{
1546 return loop_count; 1550 return loop_count;
1547} 1551}
1548 1552
1549unsigned int 1553unsigned int
1550ev_loop_depth (EV_P) 1554ev_depth (EV_P)
1551{ 1555{
1552 return loop_depth; 1556 return loop_depth;
1553} 1557}
1554 1558
1555void 1559void
1627 1631
1628 ev_rt_now = ev_time (); 1632 ev_rt_now = ev_time ();
1629 mn_now = get_clock (); 1633 mn_now = get_clock ();
1630 now_floor = mn_now; 1634 now_floor = mn_now;
1631 rtmn_diff = ev_rt_now - mn_now; 1635 rtmn_diff = ev_rt_now - mn_now;
1632#if EV_MINIMAL < 2 1636#if EV_FEATURE_API
1633 invoke_cb = ev_invoke_pending; 1637 invoke_cb = ev_invoke_pending;
1634#endif 1638#endif
1635 1639
1636 io_blocktime = 0.; 1640 io_blocktime = 0.;
1637 timeout_blocktime = 0.; 1641 timeout_blocktime = 0.;
1874 verify_watcher (EV_A_ ws [cnt]); 1878 verify_watcher (EV_A_ ws [cnt]);
1875 } 1879 }
1876} 1880}
1877#endif 1881#endif
1878 1882
1879#if EV_MINIMAL < 2 1883#if EV_FEATURE_API
1880void 1884void
1881ev_loop_verify (EV_P) 1885ev_verify (EV_P)
1882{ 1886{
1883#if EV_VERIFY 1887#if EV_VERIFY
1884 int i; 1888 int i;
1885 WL w; 1889 WL w;
1886 1890
1937 array_verify (EV_A_ (W *)checks, checkcnt); 1941 array_verify (EV_A_ (W *)checks, checkcnt);
1938#endif 1942#endif
1939 1943
1940# if 0 1944# if 0
1941#if EV_CHILD_ENABLE 1945#if EV_CHILD_ENABLE
1942 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)
1943 for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) 1947 for (signum = EV_NSIG; signum--; ) if (signals [signum].pending)
1944#endif 1948#endif
1945# endif 1949# endif
1946#endif 1950#endif
1947} 1951}
2104 EV_FREQUENT_CHECK; 2108 EV_FREQUENT_CHECK;
2105 feed_reverse (EV_A_ (W)w); 2109 feed_reverse (EV_A_ (W)w);
2106 } 2110 }
2107 while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); 2111 while (timercnt && ANHE_at (timers [HEAP0]) < mn_now);
2108 2112
2109 feed_reverse_done (EV_A_ EV_TIMEOUT); 2113 feed_reverse_done (EV_A_ EV_TIMER);
2110 } 2114 }
2111} 2115}
2112 2116
2113#if EV_PERIODIC_ENABLE 2117#if EV_PERIODIC_ENABLE
2114/* make periodics pending */ 2118/* make periodics pending */
2275} 2279}
2276 2280
2277void 2281void
2278ev_loop (EV_P_ int flags) 2282ev_loop (EV_P_ int flags)
2279{ 2283{
2280#if EV_MINIMAL < 2 2284#if EV_FEATURE_API
2281 ++loop_depth; 2285 ++loop_depth;
2282#endif 2286#endif
2283 2287
2284 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));
2285 2289
2288 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 */
2289 2293
2290 do 2294 do
2291 { 2295 {
2292#if EV_VERIFY >= 2 2296#if EV_VERIFY >= 2
2293 ev_loop_verify (EV_A); 2297 ev_verify (EV_A);
2294#endif 2298#endif
2295 2299
2296#ifndef _WIN32 2300#ifndef _WIN32
2297 if (expect_false (curpid)) /* penalise the forking check even more */ 2301 if (expect_false (curpid)) /* penalise the forking check even more */
2298 if (expect_false (getpid () != curpid)) 2302 if (expect_false (getpid () != curpid))
2378 waittime -= sleeptime; 2382 waittime -= sleeptime;
2379 } 2383 }
2380 } 2384 }
2381 } 2385 }
2382 2386
2383#if EV_MINIMAL < 2 2387#if EV_FEATURE_API
2384 ++loop_count; 2388 ++loop_count;
2385#endif 2389#endif
2386 assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ 2390 assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */
2387 backend_poll (EV_A_ waittime); 2391 backend_poll (EV_A_ waittime);
2388 assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ 2392 assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */
2417 )); 2421 ));
2418 2422
2419 if (loop_done == EVUNLOOP_ONE) 2423 if (loop_done == EVUNLOOP_ONE)
2420 loop_done = EVUNLOOP_CANCEL; 2424 loop_done = EVUNLOOP_CANCEL;
2421 2425
2422#if EV_MINIMAL < 2 2426#if EV_FEATURE_API
2423 --loop_depth; 2427 --loop_depth;
2424#endif 2428#endif
2425} 2429}
2426 2430
2427void 2431void
2877 return; 2881 return;
2878 2882
2879 EV_FREQUENT_CHECK; 2883 EV_FREQUENT_CHECK;
2880 2884
2881 ev_start (EV_A_ (W)w, 1); 2885 ev_start (EV_A_ (W)w, 1);
2882 wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); 2886 wlist_add (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w);
2883 2887
2884 EV_FREQUENT_CHECK; 2888 EV_FREQUENT_CHECK;
2885} 2889}
2886 2890
2887void 2891void
2891 if (expect_false (!ev_is_active (w))) 2895 if (expect_false (!ev_is_active (w)))
2892 return; 2896 return;
2893 2897
2894 EV_FREQUENT_CHECK; 2898 EV_FREQUENT_CHECK;
2895 2899
2896 wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); 2900 wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w);
2897 ev_stop (EV_A_ (W)w); 2901 ev_stop (EV_A_ (W)w);
2898 2902
2899 EV_FREQUENT_CHECK; 2903 EV_FREQUENT_CHECK;
2900} 2904}
2901 2905
2974 while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); 2978 while (w->wd < 0 && (errno == ENOENT || errno == EACCES));
2975 } 2979 }
2976 } 2980 }
2977 2981
2978 if (w->wd >= 0) 2982 if (w->wd >= 0)
2979 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);
2980 2984
2981 /* now re-arm timer, if required */ 2985 /* now re-arm timer, if required */
2982 if (ev_is_active (&w->timer)) ev_ref (EV_A); 2986 if (ev_is_active (&w->timer)) ev_ref (EV_A);
2983 ev_timer_again (EV_A_ &w->timer); 2987 ev_timer_again (EV_A_ &w->timer);
2984 if (ev_is_active (&w->timer)) ev_unref (EV_A); 2988 if (ev_is_active (&w->timer)) ev_unref (EV_A);
2992 2996
2993 if (wd < 0) 2997 if (wd < 0)
2994 return; 2998 return;
2995 2999
2996 w->wd = -2; 3000 w->wd = -2;
2997 slot = wd & (EV_INOTIFY_HASHSIZE - 1); 3001 slot = wd & ((EV_INOTIFY_HASHSIZE) - 1);
2998 wlist_del (&fs_hash [slot].head, (WL)w); 3002 wlist_del (&fs_hash [slot].head, (WL)w);
2999 3003
3000 /* remove this watcher, if others are watching it, they will rearm */ 3004 /* remove this watcher, if others are watching it, they will rearm */
3001 inotify_rm_watch (fs_fd, wd); 3005 inotify_rm_watch (fs_fd, wd);
3002} 3006}
3004static void noinline 3008static void noinline
3005infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) 3009infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev)
3006{ 3010{
3007 if (slot < 0) 3011 if (slot < 0)
3008 /* overflow, need to check for all hash slots */ 3012 /* overflow, need to check for all hash slots */
3009 for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) 3013 for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot)
3010 infy_wd (EV_A_ slot, wd, ev); 3014 infy_wd (EV_A_ slot, wd, ev);
3011 else 3015 else
3012 { 3016 {
3013 WL w_; 3017 WL w_;
3014 3018
3015 for (w_ = fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head; w_; ) 3019 for (w_ = fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head; w_; )
3016 { 3020 {
3017 ev_stat *w = (ev_stat *)w_; 3021 ev_stat *w = (ev_stat *)w_;
3018 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 */
3019 3023
3020 if (w->wd == wd || wd == -1) 3024 if (w->wd == wd || wd == -1)
3021 { 3025 {
3022 if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) 3026 if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF))
3023 { 3027 {
3024 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);
3025 w->wd = -1; 3029 w->wd = -1;
3026 infy_add (EV_A_ w); /* re-add, no matter what */ 3030 infy_add (EV_A_ w); /* re-add, no matter what */
3027 } 3031 }
3028 3032
3029 stat_timer_cb (EV_A_ &w->timer, 0); 3033 stat_timer_cb (EV_A_ &w->timer, 0);
3143 ev_io_set (&fs_w, fs_fd, EV_READ); 3147 ev_io_set (&fs_w, fs_fd, EV_READ);
3144 ev_io_start (EV_A_ &fs_w); 3148 ev_io_start (EV_A_ &fs_w);
3145 ev_unref (EV_A); 3149 ev_unref (EV_A);
3146 } 3150 }
3147 3151
3148 for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) 3152 for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot)
3149 { 3153 {
3150 WL w_ = fs_hash [slot].head; 3154 WL w_ = fs_hash [slot].head;
3151 fs_hash [slot].head = 0; 3155 fs_hash [slot].head = 0;
3152 3156
3153 while (w_) 3157 while (w_)
3644{ 3648{
3645 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));
3646 3650
3647 if (expect_false (!once)) 3651 if (expect_false (!once))
3648 { 3652 {
3649 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); 3653 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg);
3650 return; 3654 return;
3651 } 3655 }
3652 3656
3653 once->cb = cb; 3657 once->cb = cb;
3654 once->arg = arg; 3658 once->arg = arg;
3769 } 3773 }
3770#endif 3774#endif
3771 3775
3772#if EV_CHILD_ENABLE 3776#if EV_CHILD_ENABLE
3773 if (types & EV_CHILD) 3777 if (types & EV_CHILD)
3774 for (i = EV_PID_HASHSIZE; i--; ) 3778 for (i = (EV_PID_HASHSIZE); i--; )
3775 for (wl = childs [i]; wl; ) 3779 for (wl = childs [i]; wl; )
3776 { 3780 {
3777 wn = wl->next; 3781 wn = wl->next;
3778 cb (EV_A_ EV_CHILD, wl); 3782 cb (EV_A_ EV_CHILD, wl);
3779 wl = wn; 3783 wl = wn;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines