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

Comparing libev/ev.c (file contents):
Revision 1.332 by root, Tue Mar 9 08:58:17 2010 UTC vs.
Revision 1.346 by root, Thu Oct 14 05:07:04 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)
207#elif defined (MAXSIG) 224#elif defined (MAXSIG)
208# define EV_NSIG (MAXSIG+1) 225# define EV_NSIG (MAXSIG+1)
209#elif defined (MAX_SIG) 226#elif defined (MAX_SIG)
210# define EV_NSIG (MAX_SIG+1) 227# define EV_NSIG (MAX_SIG+1)
211#elif defined (SIGARRAYSIZE) 228#elif defined (SIGARRAYSIZE)
212# define EV_NSIG SIGARRAYSIZE /* Assume ary[SIGARRAYSIZE] */ 229# define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */
213#elif defined (_sys_nsig) 230#elif defined (_sys_nsig)
214# define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ 231# define EV_NSIG (_sys_nsig) /* Solaris 2.5 */
215#else 232#else
216# error "unable to find value for NSIG, please report" 233# error "unable to find value for NSIG, please report"
217/* to make it compile regardless, just remove the above line */ 234/* to make it compile regardless, just remove the above line, */
235/* but consider reporting it, too! :) */
218# define EV_NSIG 65 236# define EV_NSIG 65
219#endif 237#endif
220 238
221#ifndef EV_USE_CLOCK_SYSCALL 239#ifndef EV_USE_CLOCK_SYSCALL
222# if __linux && __GLIBC__ >= 2 240# if __linux && __GLIBC__ >= 2
223# define EV_USE_CLOCK_SYSCALL 1 241# define EV_USE_CLOCK_SYSCALL EV_FEATURE_OS
224# else 242# else
225# define EV_USE_CLOCK_SYSCALL 0 243# define EV_USE_CLOCK_SYSCALL 0
226# endif 244# endif
227#endif 245#endif
228 246
229#ifndef EV_USE_MONOTONIC 247#ifndef EV_USE_MONOTONIC
230# if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 248# if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0
231# define EV_USE_MONOTONIC 1 249# define EV_USE_MONOTONIC EV_FEATURE_OS
232# else 250# else
233# define EV_USE_MONOTONIC 0 251# define EV_USE_MONOTONIC 0
234# endif 252# endif
235#endif 253#endif
236 254
238# define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL 256# define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL
239#endif 257#endif
240 258
241#ifndef EV_USE_NANOSLEEP 259#ifndef EV_USE_NANOSLEEP
242# if _POSIX_C_SOURCE >= 199309L 260# if _POSIX_C_SOURCE >= 199309L
243# define EV_USE_NANOSLEEP 1 261# define EV_USE_NANOSLEEP EV_FEATURE_OS
244# else 262# else
245# define EV_USE_NANOSLEEP 0 263# define EV_USE_NANOSLEEP 0
246# endif 264# endif
247#endif 265#endif
248 266
249#ifndef EV_USE_SELECT 267#ifndef EV_USE_SELECT
250# define EV_USE_SELECT 1 268# define EV_USE_SELECT EV_FEATURE_BACKENDS
251#endif 269#endif
252 270
253#ifndef EV_USE_POLL 271#ifndef EV_USE_POLL
254# ifdef _WIN32 272# ifdef _WIN32
255# define EV_USE_POLL 0 273# define EV_USE_POLL 0
256# else 274# else
257# define EV_USE_POLL 1 275# define EV_USE_POLL EV_FEATURE_BACKENDS
258# endif 276# endif
259#endif 277#endif
260 278
261#ifndef EV_USE_EPOLL 279#ifndef EV_USE_EPOLL
262# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) 280# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
263# define EV_USE_EPOLL 1 281# define EV_USE_EPOLL EV_FEATURE_BACKENDS
264# else 282# else
265# define EV_USE_EPOLL 0 283# define EV_USE_EPOLL 0
266# endif 284# endif
267#endif 285#endif
268 286
274# define EV_USE_PORT 0 292# define EV_USE_PORT 0
275#endif 293#endif
276 294
277#ifndef EV_USE_INOTIFY 295#ifndef EV_USE_INOTIFY
278# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) 296# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
279# define EV_USE_INOTIFY 1 297# define EV_USE_INOTIFY EV_FEATURE_OS
280# else 298# else
281# define EV_USE_INOTIFY 0 299# define EV_USE_INOTIFY 0
282# endif 300# endif
283#endif 301#endif
284 302
285#ifndef EV_PID_HASHSIZE 303#ifndef EV_PID_HASHSIZE
286# if EV_MINIMAL 304# define EV_PID_HASHSIZE EV_FEATURE_DATA ? 16 : 1
287# define EV_PID_HASHSIZE 1
288# else
289# define EV_PID_HASHSIZE 16
290# endif
291#endif 305#endif
292 306
293#ifndef EV_INOTIFY_HASHSIZE 307#ifndef EV_INOTIFY_HASHSIZE
294# if EV_MINIMAL 308# define EV_INOTIFY_HASHSIZE EV_FEATURE_DATA ? 16 : 1
295# define EV_INOTIFY_HASHSIZE 1
296# else
297# define EV_INOTIFY_HASHSIZE 16
298# endif
299#endif 309#endif
300 310
301#ifndef EV_USE_EVENTFD 311#ifndef EV_USE_EVENTFD
302# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) 312# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7))
303# define EV_USE_EVENTFD 1 313# define EV_USE_EVENTFD EV_FEATURE_OS
304# else 314# else
305# define EV_USE_EVENTFD 0 315# define EV_USE_EVENTFD 0
306# endif 316# endif
307#endif 317#endif
308 318
309#ifndef EV_USE_SIGNALFD 319#ifndef EV_USE_SIGNALFD
310# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) 320# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7))
311# define EV_USE_SIGNALFD 1 321# define EV_USE_SIGNALFD EV_FEATURE_OS
312# else 322# else
313# define EV_USE_SIGNALFD 0 323# define EV_USE_SIGNALFD 0
314# endif 324# endif
315#endif 325#endif
316 326
319# define EV_USE_4HEAP 1 329# define EV_USE_4HEAP 1
320# define EV_HEAP_CACHE_AT 1 330# define EV_HEAP_CACHE_AT 1
321#endif 331#endif
322 332
323#ifndef EV_VERIFY 333#ifndef EV_VERIFY
324# define EV_VERIFY !EV_MINIMAL 334# define EV_VERIFY (EV_FEATURE_API ? 1 : 0)
325#endif 335#endif
326 336
327#ifndef EV_USE_4HEAP 337#ifndef EV_USE_4HEAP
328# define EV_USE_4HEAP !EV_MINIMAL 338# define EV_USE_4HEAP EV_FEATURE_DATA
329#endif 339#endif
330 340
331#ifndef EV_HEAP_CACHE_AT 341#ifndef EV_HEAP_CACHE_AT
332# define EV_HEAP_CACHE_AT !EV_MINIMAL 342# define EV_HEAP_CACHE_AT EV_FEATURE_DATA
333#endif 343#endif
334 344
335/* 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, */
336/* which makes programs even slower. might work on other unices, too. */ 346/* which makes programs even slower. might work on other unices, too. */
337#if EV_USE_CLOCK_SYSCALL 347#if EV_USE_CLOCK_SYSCALL
442 452
443 453
444/**/ 454/**/
445 455
446#if EV_VERIFY >= 3 456#if EV_VERIFY >= 3
447# define EV_FREQUENT_CHECK ev_loop_verify (EV_A) 457# define EV_FREQUENT_CHECK ev_verify (EV_A)
448#else 458#else
449# define EV_FREQUENT_CHECK do { } while (0) 459# define EV_FREQUENT_CHECK do { } while (0)
450#endif 460#endif
451 461
452/* 462/*
475 485
476#define expect_false(expr) expect ((expr) != 0, 0) 486#define expect_false(expr) expect ((expr) != 0, 0)
477#define expect_true(expr) expect ((expr) != 0, 1) 487#define expect_true(expr) expect ((expr) != 0, 1)
478#define inline_size static inline 488#define inline_size static inline
479 489
480#if EV_MINIMAL 490#if EV_FEATURE_CODE
491# define inline_speed static inline
492#else
481# define inline_speed static noinline 493# define inline_speed static noinline
482#else
483# define inline_speed static inline
484#endif 494#endif
485 495
486#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) 496#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
487 497
488#if EV_MINPRI == EV_MAXPRI 498#if EV_MINPRI == EV_MAXPRI
501#define ev_active(w) ((W)(w))->active 511#define ev_active(w) ((W)(w))->active
502#define ev_at(w) ((WT)(w))->at 512#define ev_at(w) ((WT)(w))->at
503 513
504#if EV_USE_REALTIME 514#if EV_USE_REALTIME
505/* sig_atomic_t is used to avoid per-thread variables or locking but still */ 515/* sig_atomic_t is used to avoid per-thread variables or locking but still */
506/* giving it a reasonably high chance of working on typical architetcures */ 516/* giving it a reasonably high chance of working on typical architectures */
507static EV_ATOMIC_T have_realtime; /* did clock_gettime (CLOCK_REALTIME) work? */ 517static EV_ATOMIC_T have_realtime; /* did clock_gettime (CLOCK_REALTIME) work? */
508#endif 518#endif
509 519
510#if EV_USE_MONOTONIC 520#if EV_USE_MONOTONIC
511static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 521static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
568} 578}
569 579
570static void * 580static void *
571ev_realloc_emul (void *ptr, long size) 581ev_realloc_emul (void *ptr, long size)
572{ 582{
583#if __GLIBC__
584 return realloc (ptr, size);
585#else
573 /* some systems, notably openbsd and darwin, fail to properly 586 /* some systems, notably openbsd and darwin, fail to properly
574 * implement realloc (x, 0) (as required by both ansi c-98 and 587 * implement realloc (x, 0) (as required by both ansi c-89 and
575 * the single unix specification, so work around them here. 588 * the single unix specification, so work around them here.
576 */ 589 */
590
577 if (size) 591 if (size)
578 return realloc (ptr, size); 592 return realloc (ptr, size);
579 593
580 free (ptr); 594 free (ptr);
581 return 0; 595 return 0;
596#endif
582} 597}
583 598
584static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; 599static void *(*alloc)(void *ptr, long size) = ev_realloc_emul;
585 600
586void 601void
690 705
691 static int ev_default_loop_ptr; 706 static int ev_default_loop_ptr;
692 707
693#endif 708#endif
694 709
695#if EV_MINIMAL < 2 710#if EV_FEATURE_API
696# 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)
697# 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)
698# define EV_INVOKE_PENDING invoke_cb (EV_A) 713# define EV_INVOKE_PENDING invoke_cb (EV_A)
699#else 714#else
700# define EV_RELEASE_CB (void)0 715# define EV_RELEASE_CB (void)0
779/*****************************************************************************/ 794/*****************************************************************************/
780 795
781#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ 796#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */
782 797
783/* find a suitable new size for the given array, */ 798/* find a suitable new size for the given array, */
784/* hopefully by rounding to a ncie-to-malloc size */ 799/* hopefully by rounding to a nice-to-malloc size */
785inline_size int 800inline_size int
786array_nextsize (int elem, int cur, int cnt) 801array_nextsize (int elem, int cur, int cnt)
787{ 802{
788 int ncur = cur + 1; 803 int ncur = cur + 1;
789 804
885} 900}
886 901
887/*****************************************************************************/ 902/*****************************************************************************/
888 903
889inline_speed void 904inline_speed void
890fd_event_nc (EV_P_ int fd, int revents) 905fd_event_nocheck (EV_P_ int fd, int revents)
891{ 906{
892 ANFD *anfd = anfds + fd; 907 ANFD *anfd = anfds + fd;
893 ev_io *w; 908 ev_io *w;
894 909
895 for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) 910 for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next)
907fd_event (EV_P_ int fd, int revents) 922fd_event (EV_P_ int fd, int revents)
908{ 923{
909 ANFD *anfd = anfds + fd; 924 ANFD *anfd = anfds + fd;
910 925
911 if (expect_true (!anfd->reify)) 926 if (expect_true (!anfd->reify))
912 fd_event_nc (EV_A_ fd, revents); 927 fd_event_nocheck (EV_A_ fd, revents);
913} 928}
914 929
915void 930void
916ev_feed_fd_event (EV_P_ int fd, int revents) 931ev_feed_fd_event (EV_P_ int fd, int revents)
917{ 932{
918 if (fd >= 0 && fd < anfdmax) 933 if (fd >= 0 && fd < anfdmax)
919 fd_event_nc (EV_A_ fd, revents); 934 fd_event_nocheck (EV_A_ fd, revents);
920} 935}
921 936
922/* make sure the external fd watch events are in-sync */ 937/* make sure the external fd watch events are in-sync */
923/* with the kernel/libev internal state */ 938/* with the kernel/libev internal state */
924inline_size void 939inline_size void
987 ev_io_stop (EV_A_ w); 1002 ev_io_stop (EV_A_ w);
988 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); 1003 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
989 } 1004 }
990} 1005}
991 1006
992/* check whether the given fd is atcually valid, for error recovery */ 1007/* check whether the given fd is actually valid, for error recovery */
993inline_size int 1008inline_size int
994fd_valid (int fd) 1009fd_valid (int fd)
995{ 1010{
996#ifdef _WIN32 1011#ifdef _WIN32
997 return EV_FD_TO_WIN32_HANDLE (fd) != -1; 1012 return EV_FD_TO_WIN32_HANDLE (fd) != -1;
1039 anfds [fd].emask = 0; 1054 anfds [fd].emask = 0;
1040 fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); 1055 fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY);
1041 } 1056 }
1042} 1057}
1043 1058
1059/* used to prepare libev internal fd's */
1060/* this is not fork-safe */
1061inline_speed void
1062fd_intern (int fd)
1063{
1064#ifdef _WIN32
1065 unsigned long arg = 1;
1066 ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg);
1067#else
1068 fcntl (fd, F_SETFD, FD_CLOEXEC);
1069 fcntl (fd, F_SETFL, O_NONBLOCK);
1070#endif
1071}
1072
1044/*****************************************************************************/ 1073/*****************************************************************************/
1045 1074
1046/* 1075/*
1047 * the heap functions want a real array index. array index 0 uis guaranteed to not 1076 * the heap functions want a real array index. array index 0 is guaranteed to not
1048 * be in-use at any time. the first heap entry is at array [HEAP0]. DHEAP gives 1077 * be in-use at any time. the first heap entry is at array [HEAP0]. DHEAP gives
1049 * the branching factor of the d-tree. 1078 * the branching factor of the d-tree.
1050 */ 1079 */
1051 1080
1052/* 1081/*
1200 1229
1201static ANSIG signals [EV_NSIG - 1]; 1230static ANSIG signals [EV_NSIG - 1];
1202 1231
1203/*****************************************************************************/ 1232/*****************************************************************************/
1204 1233
1205/* used to prepare libev internal fd's */ 1234#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
1206/* this is not fork-safe */
1207inline_speed void
1208fd_intern (int fd)
1209{
1210#ifdef _WIN32
1211 unsigned long arg = 1;
1212 ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg);
1213#else
1214 fcntl (fd, F_SETFD, FD_CLOEXEC);
1215 fcntl (fd, F_SETFL, O_NONBLOCK);
1216#endif
1217}
1218 1235
1219static void noinline 1236static void noinline
1220evpipe_init (EV_P) 1237evpipe_init (EV_P)
1221{ 1238{
1222 if (!ev_is_active (&pipe_w)) 1239 if (!ev_is_active (&pipe_w))
1223 { 1240 {
1224#if EV_USE_EVENTFD 1241# if EV_USE_EVENTFD
1225 evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); 1242 evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC);
1226 if (evfd < 0 && errno == EINVAL) 1243 if (evfd < 0 && errno == EINVAL)
1227 evfd = eventfd (0, 0); 1244 evfd = eventfd (0, 0);
1228 1245
1229 if (evfd >= 0) 1246 if (evfd >= 0)
1231 evpipe [0] = -1; 1248 evpipe [0] = -1;
1232 fd_intern (evfd); /* doing it twice doesn't hurt */ 1249 fd_intern (evfd); /* doing it twice doesn't hurt */
1233 ev_io_set (&pipe_w, evfd, EV_READ); 1250 ev_io_set (&pipe_w, evfd, EV_READ);
1234 } 1251 }
1235 else 1252 else
1236#endif 1253# endif
1237 { 1254 {
1238 while (pipe (evpipe)) 1255 while (pipe (evpipe))
1239 ev_syserr ("(libev) error creating signal/async pipe"); 1256 ev_syserr ("(libev) error creating signal/async pipe");
1240 1257
1241 fd_intern (evpipe [0]); 1258 fd_intern (evpipe [0]);
1252evpipe_write (EV_P_ EV_ATOMIC_T *flag) 1269evpipe_write (EV_P_ EV_ATOMIC_T *flag)
1253{ 1270{
1254 if (!*flag) 1271 if (!*flag)
1255 { 1272 {
1256 int old_errno = errno; /* save errno because write might clobber it */ 1273 int old_errno = errno; /* save errno because write might clobber it */
1274 char dummy;
1257 1275
1258 *flag = 1; 1276 *flag = 1;
1259 1277
1260#if EV_USE_EVENTFD 1278#if EV_USE_EVENTFD
1261 if (evfd >= 0) 1279 if (evfd >= 0)
1263 uint64_t counter = 1; 1281 uint64_t counter = 1;
1264 write (evfd, &counter, sizeof (uint64_t)); 1282 write (evfd, &counter, sizeof (uint64_t));
1265 } 1283 }
1266 else 1284 else
1267#endif 1285#endif
1286 /* win32 people keep sending patches that change this write() to send() */
1287 /* and then run away. but send() is wrong, it wants a socket handle on win32 */
1288 /* so when you think this write should be a send instead, please find out */
1289 /* where your send() is from - it's definitely not the microsoft send, and */
1290 /* tell me. thank you. */
1268 write (evpipe [1], &old_errno, 1); 1291 write (evpipe [1], &dummy, 1);
1269 1292
1270 errno = old_errno; 1293 errno = old_errno;
1271 } 1294 }
1272} 1295}
1273 1296
1286 } 1309 }
1287 else 1310 else
1288#endif 1311#endif
1289 { 1312 {
1290 char dummy; 1313 char dummy;
1314 /* see discussion in evpipe_write when you think this read should be recv in win32 */
1291 read (evpipe [0], &dummy, 1); 1315 read (evpipe [0], &dummy, 1);
1292 } 1316 }
1293 1317
1294 if (sig_pending) 1318 if (sig_pending)
1295 { 1319 {
1374 break; 1398 break;
1375 } 1399 }
1376} 1400}
1377#endif 1401#endif
1378 1402
1403#endif
1404
1379/*****************************************************************************/ 1405/*****************************************************************************/
1380 1406
1407#if EV_CHILD_ENABLE
1381static WL childs [EV_PID_HASHSIZE]; 1408static WL childs [EV_PID_HASHSIZE];
1382
1383#ifndef _WIN32
1384 1409
1385static ev_signal childev; 1410static ev_signal childev;
1386 1411
1387#ifndef WIFCONTINUED 1412#ifndef WIFCONTINUED
1388# define WIFCONTINUED(status) 0 1413# define WIFCONTINUED(status) 0
1393child_reap (EV_P_ int chain, int pid, int status) 1418child_reap (EV_P_ int chain, int pid, int status)
1394{ 1419{
1395 ev_child *w; 1420 ev_child *w;
1396 int traced = WIFSTOPPED (status) || WIFCONTINUED (status); 1421 int traced = WIFSTOPPED (status) || WIFCONTINUED (status);
1397 1422
1398 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) 1423 for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next)
1399 { 1424 {
1400 if ((w->pid == pid || !w->pid) 1425 if ((w->pid == pid || !w->pid)
1401 && (!traced || (w->flags & 1))) 1426 && (!traced || (w->flags & 1)))
1402 { 1427 {
1403 ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ 1428 ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */
1428 /* make sure we are called again until all children have been reaped */ 1453 /* make sure we are called again until all children have been reaped */
1429 /* we need to do it this way so that the callback gets called before we continue */ 1454 /* we need to do it this way so that the callback gets called before we continue */
1430 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); 1455 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
1431 1456
1432 child_reap (EV_A_ pid, pid, status); 1457 child_reap (EV_A_ pid, pid, status);
1433 if (EV_PID_HASHSIZE > 1) 1458 if ((EV_PID_HASHSIZE) > 1)
1434 child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ 1459 child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */
1435} 1460}
1436 1461
1437#endif 1462#endif
1438 1463
1505#ifdef __APPLE__ 1530#ifdef __APPLE__
1506 /* only select works correctly on that "unix-certified" platform */ 1531 /* only select works correctly on that "unix-certified" platform */
1507 flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ 1532 flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */
1508 flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ 1533 flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */
1509#endif 1534#endif
1535#ifdef __FreeBSD__
1536 flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */
1537#endif
1510 1538
1511 return flags; 1539 return flags;
1512} 1540}
1513 1541
1514unsigned int 1542unsigned int
1527ev_backend (EV_P) 1555ev_backend (EV_P)
1528{ 1556{
1529 return backend; 1557 return backend;
1530} 1558}
1531 1559
1532#if EV_MINIMAL < 2 1560#if EV_FEATURE_API
1533unsigned int 1561unsigned int
1534ev_loop_count (EV_P) 1562ev_iteration (EV_P)
1535{ 1563{
1536 return loop_count; 1564 return loop_count;
1537} 1565}
1538 1566
1539unsigned int 1567unsigned int
1540ev_loop_depth (EV_P) 1568ev_depth (EV_P)
1541{ 1569{
1542 return loop_depth; 1570 return loop_depth;
1543} 1571}
1544 1572
1545void 1573void
1617 1645
1618 ev_rt_now = ev_time (); 1646 ev_rt_now = ev_time ();
1619 mn_now = get_clock (); 1647 mn_now = get_clock ();
1620 now_floor = mn_now; 1648 now_floor = mn_now;
1621 rtmn_diff = ev_rt_now - mn_now; 1649 rtmn_diff = ev_rt_now - mn_now;
1622#if EV_MINIMAL < 2 1650#if EV_FEATURE_API
1623 invoke_cb = ev_invoke_pending; 1651 invoke_cb = ev_invoke_pending;
1624#endif 1652#endif
1625 1653
1626 io_blocktime = 0.; 1654 io_blocktime = 0.;
1627 timeout_blocktime = 0.; 1655 timeout_blocktime = 0.;
1657 if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); 1685 if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags);
1658#endif 1686#endif
1659 1687
1660 ev_prepare_init (&pending_w, pendingcb); 1688 ev_prepare_init (&pending_w, pendingcb);
1661 1689
1690#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
1662 ev_init (&pipe_w, pipecb); 1691 ev_init (&pipe_w, pipecb);
1663 ev_set_priority (&pipe_w, EV_MAXPRI); 1692 ev_set_priority (&pipe_w, EV_MAXPRI);
1693#endif
1664 } 1694 }
1665} 1695}
1666 1696
1667/* free up a loop structure */ 1697/* free up a loop structure */
1668static void noinline 1698static void noinline
1786 { 1816 {
1787 EV_WIN32_CLOSE_FD (evpipe [0]); 1817 EV_WIN32_CLOSE_FD (evpipe [0]);
1788 EV_WIN32_CLOSE_FD (evpipe [1]); 1818 EV_WIN32_CLOSE_FD (evpipe [1]);
1789 } 1819 }
1790 1820
1821#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
1791 evpipe_init (EV_A); 1822 evpipe_init (EV_A);
1792 /* now iterate over everything, in case we missed something */ 1823 /* now iterate over everything, in case we missed something */
1793 pipecb (EV_A_ &pipe_w, EV_READ); 1824 pipecb (EV_A_ &pipe_w, EV_READ);
1825#endif
1794 } 1826 }
1795 1827
1796 postfork = 0; 1828 postfork = 0;
1797} 1829}
1798 1830
1860 verify_watcher (EV_A_ ws [cnt]); 1892 verify_watcher (EV_A_ ws [cnt]);
1861 } 1893 }
1862} 1894}
1863#endif 1895#endif
1864 1896
1865#if EV_MINIMAL < 2 1897#if EV_FEATURE_API
1866void 1898void
1867ev_loop_verify (EV_P) 1899ev_verify (EV_P)
1868{ 1900{
1869#if EV_VERIFY 1901#if EV_VERIFY
1870 int i; 1902 int i;
1871 WL w; 1903 WL w;
1872 1904
1911#if EV_ASYNC_ENABLE 1943#if EV_ASYNC_ENABLE
1912 assert (asyncmax >= asynccnt); 1944 assert (asyncmax >= asynccnt);
1913 array_verify (EV_A_ (W *)asyncs, asynccnt); 1945 array_verify (EV_A_ (W *)asyncs, asynccnt);
1914#endif 1946#endif
1915 1947
1948#if EV_PREPARE_ENABLE
1916 assert (preparemax >= preparecnt); 1949 assert (preparemax >= preparecnt);
1917 array_verify (EV_A_ (W *)prepares, preparecnt); 1950 array_verify (EV_A_ (W *)prepares, preparecnt);
1951#endif
1918 1952
1953#if EV_CHECK_ENABLE
1919 assert (checkmax >= checkcnt); 1954 assert (checkmax >= checkcnt);
1920 array_verify (EV_A_ (W *)checks, checkcnt); 1955 array_verify (EV_A_ (W *)checks, checkcnt);
1956#endif
1921 1957
1922# if 0 1958# if 0
1959#if EV_CHILD_ENABLE
1923 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) 1960 for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next)
1924 for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) 1961 for (signum = EV_NSIG; signum--; ) if (signals [signum].pending)
1962#endif
1925# endif 1963# endif
1926#endif 1964#endif
1927} 1965}
1928#endif 1966#endif
1929 1967
1945 1983
1946 loop_init (EV_A_ flags); 1984 loop_init (EV_A_ flags);
1947 1985
1948 if (ev_backend (EV_A)) 1986 if (ev_backend (EV_A))
1949 { 1987 {
1950#ifndef _WIN32 1988#if EV_CHILD_ENABLE
1951 ev_signal_init (&childev, childcb, SIGCHLD); 1989 ev_signal_init (&childev, childcb, SIGCHLD);
1952 ev_set_priority (&childev, EV_MAXPRI); 1990 ev_set_priority (&childev, EV_MAXPRI);
1953 ev_signal_start (EV_A_ &childev); 1991 ev_signal_start (EV_A_ &childev);
1954 ev_unref (EV_A); /* child watcher should not keep loop alive */ 1992 ev_unref (EV_A); /* child watcher should not keep loop alive */
1955#endif 1993#endif
1968 EV_P = ev_default_loop_ptr; 2006 EV_P = ev_default_loop_ptr;
1969#endif 2007#endif
1970 2008
1971 ev_default_loop_ptr = 0; 2009 ev_default_loop_ptr = 0;
1972 2010
1973#ifndef _WIN32 2011#if EV_CHILD_ENABLE
1974 ev_ref (EV_A); /* child watcher */ 2012 ev_ref (EV_A); /* child watcher */
1975 ev_signal_stop (EV_A_ &childev); 2013 ev_signal_stop (EV_A_ &childev);
1976#endif 2014#endif
1977 2015
1978 loop_destroy (EV_A); 2016 loop_destroy (EV_A);
2084 EV_FREQUENT_CHECK; 2122 EV_FREQUENT_CHECK;
2085 feed_reverse (EV_A_ (W)w); 2123 feed_reverse (EV_A_ (W)w);
2086 } 2124 }
2087 while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); 2125 while (timercnt && ANHE_at (timers [HEAP0]) < mn_now);
2088 2126
2089 feed_reverse_done (EV_A_ EV_TIMEOUT); 2127 feed_reverse_done (EV_A_ EV_TIMER);
2090 } 2128 }
2091} 2129}
2092 2130
2093#if EV_PERIODIC_ENABLE 2131#if EV_PERIODIC_ENABLE
2094/* make periodics pending */ 2132/* make periodics pending */
2147 feed_reverse_done (EV_A_ EV_PERIODIC); 2185 feed_reverse_done (EV_A_ EV_PERIODIC);
2148 } 2186 }
2149} 2187}
2150 2188
2151/* simply recalculate all periodics */ 2189/* simply recalculate all periodics */
2152/* TODO: maybe ensure that at leats one event happens when jumping forward? */ 2190/* TODO: maybe ensure that at least one event happens when jumping forward? */
2153static void noinline 2191static void noinline
2154periodics_reschedule (EV_P) 2192periodics_reschedule (EV_P)
2155{ 2193{
2156 int i; 2194 int i;
2157 2195
2255} 2293}
2256 2294
2257void 2295void
2258ev_loop (EV_P_ int flags) 2296ev_loop (EV_P_ int flags)
2259{ 2297{
2260#if EV_MINIMAL < 2 2298#if EV_FEATURE_API
2261 ++loop_depth; 2299 ++loop_depth;
2262#endif 2300#endif
2263 2301
2264 assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); 2302 assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE));
2265 2303
2268 EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ 2306 EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */
2269 2307
2270 do 2308 do
2271 { 2309 {
2272#if EV_VERIFY >= 2 2310#if EV_VERIFY >= 2
2273 ev_loop_verify (EV_A); 2311 ev_verify (EV_A);
2274#endif 2312#endif
2275 2313
2276#ifndef _WIN32 2314#ifndef _WIN32
2277 if (expect_false (curpid)) /* penalise the forking check even more */ 2315 if (expect_false (curpid)) /* penalise the forking check even more */
2278 if (expect_false (getpid () != curpid)) 2316 if (expect_false (getpid () != curpid))
2290 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); 2328 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK);
2291 EV_INVOKE_PENDING; 2329 EV_INVOKE_PENDING;
2292 } 2330 }
2293#endif 2331#endif
2294 2332
2333#if EV_PREPARE_ENABLE
2295 /* queue prepare watchers (and execute them) */ 2334 /* queue prepare watchers (and execute them) */
2296 if (expect_false (preparecnt)) 2335 if (expect_false (preparecnt))
2297 { 2336 {
2298 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 2337 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
2299 EV_INVOKE_PENDING; 2338 EV_INVOKE_PENDING;
2300 } 2339 }
2340#endif
2301 2341
2302 if (expect_false (loop_done)) 2342 if (expect_false (loop_done))
2303 break; 2343 break;
2304 2344
2305 /* we might have forked, so reify kernel state if necessary */ 2345 /* we might have forked, so reify kernel state if necessary */
2356 waittime -= sleeptime; 2396 waittime -= sleeptime;
2357 } 2397 }
2358 } 2398 }
2359 } 2399 }
2360 2400
2361#if EV_MINIMAL < 2 2401#if EV_FEATURE_API
2362 ++loop_count; 2402 ++loop_count;
2363#endif 2403#endif
2364 assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ 2404 assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */
2365 backend_poll (EV_A_ waittime); 2405 backend_poll (EV_A_ waittime);
2366 assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ 2406 assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */
2378#if EV_IDLE_ENABLE 2418#if EV_IDLE_ENABLE
2379 /* queue idle watchers unless other events are pending */ 2419 /* queue idle watchers unless other events are pending */
2380 idle_reify (EV_A); 2420 idle_reify (EV_A);
2381#endif 2421#endif
2382 2422
2423#if EV_CHECK_ENABLE
2383 /* queue check watchers, to be executed first */ 2424 /* queue check watchers, to be executed first */
2384 if (expect_false (checkcnt)) 2425 if (expect_false (checkcnt))
2385 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 2426 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
2427#endif
2386 2428
2387 EV_INVOKE_PENDING; 2429 EV_INVOKE_PENDING;
2388 } 2430 }
2389 while (expect_true ( 2431 while (expect_true (
2390 activecnt 2432 activecnt
2393 )); 2435 ));
2394 2436
2395 if (loop_done == EVUNLOOP_ONE) 2437 if (loop_done == EVUNLOOP_ONE)
2396 loop_done = EVUNLOOP_CANCEL; 2438 loop_done = EVUNLOOP_CANCEL;
2397 2439
2398#if EV_MINIMAL < 2 2440#if EV_FEATURE_API
2399 --loop_depth; 2441 --loop_depth;
2400#endif 2442#endif
2401} 2443}
2402 2444
2403void 2445void
2720 2762
2721#ifndef SA_RESTART 2763#ifndef SA_RESTART
2722# define SA_RESTART 0 2764# define SA_RESTART 0
2723#endif 2765#endif
2724 2766
2767#if EV_SIGNAL_ENABLE
2768
2725void noinline 2769void noinline
2726ev_signal_start (EV_P_ ev_signal *w) 2770ev_signal_start (EV_P_ ev_signal *w)
2727{ 2771{
2728 if (expect_false (ev_is_active (w))) 2772 if (expect_false (ev_is_active (w)))
2729 return; 2773 return;
2835 } 2879 }
2836 2880
2837 EV_FREQUENT_CHECK; 2881 EV_FREQUENT_CHECK;
2838} 2882}
2839 2883
2884#endif
2885
2886#if EV_CHILD_ENABLE
2887
2840void 2888void
2841ev_child_start (EV_P_ ev_child *w) 2889ev_child_start (EV_P_ ev_child *w)
2842{ 2890{
2843#if EV_MULTIPLICITY 2891#if EV_MULTIPLICITY
2844 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 2892 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
2847 return; 2895 return;
2848 2896
2849 EV_FREQUENT_CHECK; 2897 EV_FREQUENT_CHECK;
2850 2898
2851 ev_start (EV_A_ (W)w, 1); 2899 ev_start (EV_A_ (W)w, 1);
2852 wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); 2900 wlist_add (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w);
2853 2901
2854 EV_FREQUENT_CHECK; 2902 EV_FREQUENT_CHECK;
2855} 2903}
2856 2904
2857void 2905void
2861 if (expect_false (!ev_is_active (w))) 2909 if (expect_false (!ev_is_active (w)))
2862 return; 2910 return;
2863 2911
2864 EV_FREQUENT_CHECK; 2912 EV_FREQUENT_CHECK;
2865 2913
2866 wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); 2914 wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w);
2867 ev_stop (EV_A_ (W)w); 2915 ev_stop (EV_A_ (W)w);
2868 2916
2869 EV_FREQUENT_CHECK; 2917 EV_FREQUENT_CHECK;
2870} 2918}
2919
2920#endif
2871 2921
2872#if EV_STAT_ENABLE 2922#if EV_STAT_ENABLE
2873 2923
2874# ifdef _WIN32 2924# ifdef _WIN32
2875# undef lstat 2925# undef lstat
2942 while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); 2992 while (w->wd < 0 && (errno == ENOENT || errno == EACCES));
2943 } 2993 }
2944 } 2994 }
2945 2995
2946 if (w->wd >= 0) 2996 if (w->wd >= 0)
2947 wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); 2997 wlist_add (&fs_hash [w->wd & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w);
2948 2998
2949 /* now re-arm timer, if required */ 2999 /* now re-arm timer, if required */
2950 if (ev_is_active (&w->timer)) ev_ref (EV_A); 3000 if (ev_is_active (&w->timer)) ev_ref (EV_A);
2951 ev_timer_again (EV_A_ &w->timer); 3001 ev_timer_again (EV_A_ &w->timer);
2952 if (ev_is_active (&w->timer)) ev_unref (EV_A); 3002 if (ev_is_active (&w->timer)) ev_unref (EV_A);
2960 3010
2961 if (wd < 0) 3011 if (wd < 0)
2962 return; 3012 return;
2963 3013
2964 w->wd = -2; 3014 w->wd = -2;
2965 slot = wd & (EV_INOTIFY_HASHSIZE - 1); 3015 slot = wd & ((EV_INOTIFY_HASHSIZE) - 1);
2966 wlist_del (&fs_hash [slot].head, (WL)w); 3016 wlist_del (&fs_hash [slot].head, (WL)w);
2967 3017
2968 /* remove this watcher, if others are watching it, they will rearm */ 3018 /* remove this watcher, if others are watching it, they will rearm */
2969 inotify_rm_watch (fs_fd, wd); 3019 inotify_rm_watch (fs_fd, wd);
2970} 3020}
2972static void noinline 3022static void noinline
2973infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) 3023infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev)
2974{ 3024{
2975 if (slot < 0) 3025 if (slot < 0)
2976 /* overflow, need to check for all hash slots */ 3026 /* overflow, need to check for all hash slots */
2977 for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) 3027 for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot)
2978 infy_wd (EV_A_ slot, wd, ev); 3028 infy_wd (EV_A_ slot, wd, ev);
2979 else 3029 else
2980 { 3030 {
2981 WL w_; 3031 WL w_;
2982 3032
2983 for (w_ = fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head; w_; ) 3033 for (w_ = fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head; w_; )
2984 { 3034 {
2985 ev_stat *w = (ev_stat *)w_; 3035 ev_stat *w = (ev_stat *)w_;
2986 w_ = w_->next; /* lets us remove this watcher and all before it */ 3036 w_ = w_->next; /* lets us remove this watcher and all before it */
2987 3037
2988 if (w->wd == wd || wd == -1) 3038 if (w->wd == wd || wd == -1)
2989 { 3039 {
2990 if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) 3040 if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF))
2991 { 3041 {
2992 wlist_del (&fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); 3042 wlist_del (&fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w);
2993 w->wd = -1; 3043 w->wd = -1;
2994 infy_add (EV_A_ w); /* re-add, no matter what */ 3044 infy_add (EV_A_ w); /* re-add, no matter what */
2995 } 3045 }
2996 3046
2997 stat_timer_cb (EV_A_ &w->timer, 0); 3047 stat_timer_cb (EV_A_ &w->timer, 0);
3111 ev_io_set (&fs_w, fs_fd, EV_READ); 3161 ev_io_set (&fs_w, fs_fd, EV_READ);
3112 ev_io_start (EV_A_ &fs_w); 3162 ev_io_start (EV_A_ &fs_w);
3113 ev_unref (EV_A); 3163 ev_unref (EV_A);
3114 } 3164 }
3115 3165
3116 for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) 3166 for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot)
3117 { 3167 {
3118 WL w_ = fs_hash [slot].head; 3168 WL w_ = fs_hash [slot].head;
3119 fs_hash [slot].head = 0; 3169 fs_hash [slot].head = 0;
3120 3170
3121 while (w_) 3171 while (w_)
3296 3346
3297 EV_FREQUENT_CHECK; 3347 EV_FREQUENT_CHECK;
3298} 3348}
3299#endif 3349#endif
3300 3350
3351#if EV_PREPARE_ENABLE
3301void 3352void
3302ev_prepare_start (EV_P_ ev_prepare *w) 3353ev_prepare_start (EV_P_ ev_prepare *w)
3303{ 3354{
3304 if (expect_false (ev_is_active (w))) 3355 if (expect_false (ev_is_active (w)))
3305 return; 3356 return;
3331 3382
3332 ev_stop (EV_A_ (W)w); 3383 ev_stop (EV_A_ (W)w);
3333 3384
3334 EV_FREQUENT_CHECK; 3385 EV_FREQUENT_CHECK;
3335} 3386}
3387#endif
3336 3388
3389#if EV_CHECK_ENABLE
3337void 3390void
3338ev_check_start (EV_P_ ev_check *w) 3391ev_check_start (EV_P_ ev_check *w)
3339{ 3392{
3340 if (expect_false (ev_is_active (w))) 3393 if (expect_false (ev_is_active (w)))
3341 return; 3394 return;
3367 3420
3368 ev_stop (EV_A_ (W)w); 3421 ev_stop (EV_A_ (W)w);
3369 3422
3370 EV_FREQUENT_CHECK; 3423 EV_FREQUENT_CHECK;
3371} 3424}
3425#endif
3372 3426
3373#if EV_EMBED_ENABLE 3427#if EV_EMBED_ENABLE
3374void noinline 3428void noinline
3375ev_embed_sweep (EV_P_ ev_embed *w) 3429ev_embed_sweep (EV_P_ ev_embed *w)
3376{ 3430{
3608{ 3662{
3609 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 3663 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
3610 3664
3611 if (expect_false (!once)) 3665 if (expect_false (!once))
3612 { 3666 {
3613 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); 3667 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg);
3614 return; 3668 return;
3615 } 3669 }
3616 3670
3617 once->cb = cb; 3671 once->cb = cb;
3618 once->arg = arg; 3672 once->arg = arg;
3705 if (types & EV_ASYNC) 3759 if (types & EV_ASYNC)
3706 for (i = asynccnt; i--; ) 3760 for (i = asynccnt; i--; )
3707 cb (EV_A_ EV_ASYNC, asyncs [i]); 3761 cb (EV_A_ EV_ASYNC, asyncs [i]);
3708#endif 3762#endif
3709 3763
3764#if EV_PREPARE_ENABLE
3710 if (types & EV_PREPARE) 3765 if (types & EV_PREPARE)
3711 for (i = preparecnt; i--; ) 3766 for (i = preparecnt; i--; )
3712#if EV_EMBED_ENABLE 3767# if EV_EMBED_ENABLE
3713 if (ev_cb (prepares [i]) != embed_prepare_cb) 3768 if (ev_cb (prepares [i]) != embed_prepare_cb)
3714#endif 3769# endif
3715 cb (EV_A_ EV_PREPARE, prepares [i]); 3770 cb (EV_A_ EV_PREPARE, prepares [i]);
3771#endif
3716 3772
3773#if EV_CHECK_ENABLE
3717 if (types & EV_CHECK) 3774 if (types & EV_CHECK)
3718 for (i = checkcnt; i--; ) 3775 for (i = checkcnt; i--; )
3719 cb (EV_A_ EV_CHECK, checks [i]); 3776 cb (EV_A_ EV_CHECK, checks [i]);
3777#endif
3720 3778
3779#if EV_SIGNAL_ENABLE
3721 if (types & EV_SIGNAL) 3780 if (types & EV_SIGNAL)
3722 for (i = 0; i < EV_NSIG - 1; ++i) 3781 for (i = 0; i < EV_NSIG - 1; ++i)
3723 for (wl = signals [i].head; wl; ) 3782 for (wl = signals [i].head; wl; )
3724 { 3783 {
3725 wn = wl->next; 3784 wn = wl->next;
3726 cb (EV_A_ EV_SIGNAL, wl); 3785 cb (EV_A_ EV_SIGNAL, wl);
3727 wl = wn; 3786 wl = wn;
3728 } 3787 }
3788#endif
3729 3789
3790#if EV_CHILD_ENABLE
3730 if (types & EV_CHILD) 3791 if (types & EV_CHILD)
3731 for (i = EV_PID_HASHSIZE; i--; ) 3792 for (i = (EV_PID_HASHSIZE); i--; )
3732 for (wl = childs [i]; wl; ) 3793 for (wl = childs [i]; wl; )
3733 { 3794 {
3734 wn = wl->next; 3795 wn = wl->next;
3735 cb (EV_A_ EV_CHILD, wl); 3796 cb (EV_A_ EV_CHILD, wl);
3736 wl = wn; 3797 wl = wn;
3737 } 3798 }
3799#endif
3738/* EV_STAT 0x00001000 /* stat data changed */ 3800/* EV_STAT 0x00001000 /* stat data changed */
3739/* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ 3801/* EV_EMBED 0x00010000 /* embedded event loop needs sweep */
3740} 3802}
3741#endif 3803#endif
3742 3804

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines