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

Comparing libev/ev.c (file contents):
Revision 1.340 by root, Tue Mar 16 20:39:29 2010 UTC vs.
Revision 1.353 by root, Thu Oct 21 12:32:47 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 EV_FEATURE_OS 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
92# define EV_USE_SELECT EV_FEATURE_BACKENDS 102# define EV_USE_POLL EV_FEATURE_BACKENDS
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 EV_FEATURE_BACKENDS
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
110# ifndef EV_USE_EPOLL
108# define EV_USE_EPOLL EV_FEATURE_BACKENDS 111# define EV_USE_EPOLL EV_FEATURE_BACKENDS
109# else
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
119# ifndef EV_USE_KQUEUE
116# define EV_USE_KQUEUE EV_FEATURE_BACKENDS 120# define EV_USE_KQUEUE EV_FEATURE_BACKENDS
117# else
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
128# ifndef EV_USE_PORT
124# define EV_USE_PORT EV_FEATURE_BACKENDS 129# define EV_USE_PORT EV_FEATURE_BACKENDS
125# else
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
137# ifndef EV_USE_INOTIFY
132# define EV_USE_INOTIFY EV_FEATURE_OS 138# define EV_USE_INOTIFY EV_FEATURE_OS
133# else
134# define EV_USE_INOTIFY 0
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
146# ifndef EV_USE_SIGNALFD
140# define EV_USE_SIGNALFD EV_FEATURE_OS 147# define EV_USE_SIGNALFD EV_FEATURE_OS
141# else
142# define EV_USE_SIGNALFD 0
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 EV_FEATURE_OS 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)
431# ifdef __cplusplus 448# ifdef __cplusplus
432} 449}
433# endif 450# endif
434#endif 451#endif
435 452
436
437/**/ 453/**/
438 454
439#if EV_VERIFY >= 3 455#if EV_VERIFY >= 3
440# define EV_FREQUENT_CHECK ev_verify (EV_A) 456# define EV_FREQUENT_CHECK ev_verify (EV_A)
441#else 457#else
453#define TIME_EPSILON 0.0001220703125 /* 1/8192 */ 469#define TIME_EPSILON 0.0001220703125 /* 1/8192 */
454 470
455#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 471#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
456#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ 472#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */
457 473
474#define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0)
475#define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0)
476
458#if __GNUC__ >= 4 477#if __GNUC__ >= 4
459# define expect(expr,value) __builtin_expect ((expr),(value)) 478# define expect(expr,value) __builtin_expect ((expr),(value))
460# define noinline __attribute__ ((noinline)) 479# define noinline __attribute__ ((noinline))
461#else 480#else
462# define expect(expr,value) (expr) 481# define expect(expr,value) (expr)
494#define ev_active(w) ((W)(w))->active 513#define ev_active(w) ((W)(w))->active
495#define ev_at(w) ((WT)(w))->at 514#define ev_at(w) ((WT)(w))->at
496 515
497#if EV_USE_REALTIME 516#if EV_USE_REALTIME
498/* sig_atomic_t is used to avoid per-thread variables or locking but still */ 517/* sig_atomic_t is used to avoid per-thread variables or locking but still */
499/* giving it a reasonably high chance of working on typical architetcures */ 518/* giving it a reasonably high chance of working on typical architectures */
500static EV_ATOMIC_T have_realtime; /* did clock_gettime (CLOCK_REALTIME) work? */ 519static EV_ATOMIC_T have_realtime; /* did clock_gettime (CLOCK_REALTIME) work? */
501#endif 520#endif
502 521
503#if EV_USE_MONOTONIC 522#if EV_USE_MONOTONIC
504static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 523static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
698# define EV_RELEASE_CB (void)0 717# define EV_RELEASE_CB (void)0
699# define EV_ACQUIRE_CB (void)0 718# define EV_ACQUIRE_CB (void)0
700# define EV_INVOKE_PENDING ev_invoke_pending (EV_A) 719# define EV_INVOKE_PENDING ev_invoke_pending (EV_A)
701#endif 720#endif
702 721
703#define EVUNLOOP_RECURSE 0x80 722#define EVBREAK_RECURSE 0x80
704 723
705/*****************************************************************************/ 724/*****************************************************************************/
706 725
707#ifndef EV_HAVE_EV_TIME 726#ifndef EV_HAVE_EV_TIME
708ev_tstamp 727ev_tstamp
752 if (delay > 0.) 771 if (delay > 0.)
753 { 772 {
754#if EV_USE_NANOSLEEP 773#if EV_USE_NANOSLEEP
755 struct timespec ts; 774 struct timespec ts;
756 775
757 ts.tv_sec = (time_t)delay; 776 EV_TS_SET (ts, delay);
758 ts.tv_nsec = (long)((delay - (ev_tstamp)(ts.tv_sec)) * 1e9);
759
760 nanosleep (&ts, 0); 777 nanosleep (&ts, 0);
761#elif defined(_WIN32) 778#elif defined(_WIN32)
762 Sleep ((unsigned long)(delay * 1e3)); 779 Sleep ((unsigned long)(delay * 1e3));
763#else 780#else
764 struct timeval tv; 781 struct timeval tv;
765 782
766 tv.tv_sec = (time_t)delay;
767 tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6);
768
769 /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ 783 /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */
770 /* something not guaranteed by newer posix versions, but guaranteed */ 784 /* something not guaranteed by newer posix versions, but guaranteed */
771 /* by older ones */ 785 /* by older ones */
786 EV_TV_SET (tv, delay);
772 select (0, 0, 0, 0, &tv); 787 select (0, 0, 0, 0, &tv);
773#endif 788#endif
774 } 789 }
775} 790}
776 791
777/*****************************************************************************/ 792/*****************************************************************************/
778 793
779#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ 794#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */
780 795
781/* find a suitable new size for the given array, */ 796/* find a suitable new size for the given array, */
782/* hopefully by rounding to a ncie-to-malloc size */ 797/* hopefully by rounding to a nice-to-malloc size */
783inline_size int 798inline_size int
784array_nextsize (int elem, int cur, int cnt) 799array_nextsize (int elem, int cur, int cnt)
785{ 800{
786 int ncur = cur + 1; 801 int ncur = cur + 1;
787 802
928 { 943 {
929 int fd = fdchanges [i]; 944 int fd = fdchanges [i];
930 ANFD *anfd = anfds + fd; 945 ANFD *anfd = anfds + fd;
931 ev_io *w; 946 ev_io *w;
932 947
933 unsigned char events = 0; 948 unsigned char o_events = anfd->events;
949 unsigned char o_reify = anfd->reify;
934 950
935 for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) 951 anfd->reify = 0;
936 events |= (unsigned char)w->events;
937 952
938#if EV_SELECT_IS_WINSOCKET 953#if EV_SELECT_IS_WINSOCKET
939 if (events) 954 if (o_reify & EV__IOFDSET)
940 { 955 {
941 unsigned long arg; 956 unsigned long arg;
942 anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); 957 anfd->handle = EV_FD_TO_WIN32_HANDLE (fd);
943 assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); 958 assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0));
944 } 959 }
945#endif 960#endif
946 961
962 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */
947 { 963 {
948 unsigned char o_events = anfd->events;
949 unsigned char o_reify = anfd->reify;
950
951 anfd->reify = 0;
952 anfd->events = events; 964 anfd->events = 0;
953 965
954 if (o_events != events || o_reify & EV__IOFDSET) 966 for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next)
967 anfd->events |= (unsigned char)w->events;
968
969 if (o_events != anfd->events)
970 o_reify = EV__IOFDSET; /* actually |= */
971 }
972
973 if (o_reify & EV__IOFDSET)
955 backend_modify (EV_A_ fd, o_events, events); 974 backend_modify (EV_A_ fd, o_events, anfd->events);
956 }
957 } 975 }
958 976
959 fdchangecnt = 0; 977 fdchangecnt = 0;
960} 978}
961 979
1054} 1072}
1055 1073
1056/*****************************************************************************/ 1074/*****************************************************************************/
1057 1075
1058/* 1076/*
1059 * the heap functions want a real array index. array index 0 uis guaranteed to not 1077 * the heap functions want a real array index. array index 0 is guaranteed to not
1060 * be in-use at any time. the first heap entry is at array [HEAP0]. DHEAP gives 1078 * be in-use at any time. the first heap entry is at array [HEAP0]. DHEAP gives
1061 * the branching factor of the d-tree. 1079 * the branching factor of the d-tree.
1062 */ 1080 */
1063 1081
1064/* 1082/*
1264 uint64_t counter = 1; 1282 uint64_t counter = 1;
1265 write (evfd, &counter, sizeof (uint64_t)); 1283 write (evfd, &counter, sizeof (uint64_t));
1266 } 1284 }
1267 else 1285 else
1268#endif 1286#endif
1287 /* win32 people keep sending patches that change this write() to send() */
1288 /* and then run away. but send() is wrong, it wants a socket handle on win32 */
1289 /* so when you think this write should be a send instead, please find out */
1290 /* where your send() is from - it's definitely not the microsoft send, and */
1291 /* tell me. thank you. */
1269 write (evpipe [1], &dummy, 1); 1292 write (evpipe [1], &dummy, 1);
1270 1293
1271 errno = old_errno; 1294 errno = old_errno;
1272 } 1295 }
1273} 1296}
1287 } 1310 }
1288 else 1311 else
1289#endif 1312#endif
1290 { 1313 {
1291 char dummy; 1314 char dummy;
1315 /* see discussion in evpipe_write when you think this read should be recv in win32 */
1292 read (evpipe [0], &dummy, 1); 1316 read (evpipe [0], &dummy, 1);
1293 } 1317 }
1294 1318
1295 if (sig_pending) 1319 if (sig_pending)
1296 { 1320 {
1507#ifdef __APPLE__ 1531#ifdef __APPLE__
1508 /* only select works correctly on that "unix-certified" platform */ 1532 /* only select works correctly on that "unix-certified" platform */
1509 flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ 1533 flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */
1510 flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ 1534 flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */
1511#endif 1535#endif
1536#ifdef __FreeBSD__
1537 flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */
1538#endif
1512 1539
1513 return flags; 1540 return flags;
1514} 1541}
1515 1542
1516unsigned int 1543unsigned int
2096 EV_FREQUENT_CHECK; 2123 EV_FREQUENT_CHECK;
2097 feed_reverse (EV_A_ (W)w); 2124 feed_reverse (EV_A_ (W)w);
2098 } 2125 }
2099 while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); 2126 while (timercnt && ANHE_at (timers [HEAP0]) < mn_now);
2100 2127
2101 feed_reverse_done (EV_A_ EV_TIMEOUT); 2128 feed_reverse_done (EV_A_ EV_TIMER);
2102 } 2129 }
2103} 2130}
2104 2131
2105#if EV_PERIODIC_ENABLE 2132#if EV_PERIODIC_ENABLE
2106/* make periodics pending */ 2133/* make periodics pending */
2159 feed_reverse_done (EV_A_ EV_PERIODIC); 2186 feed_reverse_done (EV_A_ EV_PERIODIC);
2160 } 2187 }
2161} 2188}
2162 2189
2163/* simply recalculate all periodics */ 2190/* simply recalculate all periodics */
2164/* TODO: maybe ensure that at leats one event happens when jumping forward? */ 2191/* TODO: maybe ensure that at least one event happens when jumping forward? */
2165static void noinline 2192static void noinline
2166periodics_reschedule (EV_P) 2193periodics_reschedule (EV_P)
2167{ 2194{
2168 int i; 2195 int i;
2169 2196
2265 mn_now = ev_rt_now; 2292 mn_now = ev_rt_now;
2266 } 2293 }
2267} 2294}
2268 2295
2269void 2296void
2270ev_loop (EV_P_ int flags) 2297ev_run (EV_P_ int flags)
2271{ 2298{
2272#if EV_FEATURE_API 2299#if EV_FEATURE_API
2273 ++loop_depth; 2300 ++loop_depth;
2274#endif 2301#endif
2275 2302
2276 assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); 2303 assert (("libev: ev_loop recursion during release detected", loop_done != EVBREAK_RECURSE));
2277 2304
2278 loop_done = EVUNLOOP_CANCEL; 2305 loop_done = EVBREAK_CANCEL;
2279 2306
2280 EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ 2307 EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */
2281 2308
2282 do 2309 do
2283 { 2310 {
2326 /* calculate blocking time */ 2353 /* calculate blocking time */
2327 { 2354 {
2328 ev_tstamp waittime = 0.; 2355 ev_tstamp waittime = 0.;
2329 ev_tstamp sleeptime = 0.; 2356 ev_tstamp sleeptime = 0.;
2330 2357
2358 /* remember old timestamp for io_blocktime calculation */
2359 ev_tstamp prev_mn_now = mn_now;
2360
2361 /* update time to cancel out callback processing overhead */
2362 time_update (EV_A_ 1e100);
2363
2331 if (expect_true (!(flags & EVLOOP_NONBLOCK || idleall || !activecnt))) 2364 if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt)))
2332 { 2365 {
2333 /* remember old timestamp for io_blocktime calculation */
2334 ev_tstamp prev_mn_now = mn_now;
2335
2336 /* update time to cancel out callback processing overhead */
2337 time_update (EV_A_ 1e100);
2338
2339 waittime = MAX_BLOCKTIME; 2366 waittime = MAX_BLOCKTIME;
2340 2367
2341 if (timercnt) 2368 if (timercnt)
2342 { 2369 {
2343 ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now + backend_fudge; 2370 ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now + backend_fudge;
2373 } 2400 }
2374 2401
2375#if EV_FEATURE_API 2402#if EV_FEATURE_API
2376 ++loop_count; 2403 ++loop_count;
2377#endif 2404#endif
2378 assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ 2405 assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */
2379 backend_poll (EV_A_ waittime); 2406 backend_poll (EV_A_ waittime);
2380 assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ 2407 assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */
2381 2408
2382 /* update ev_rt_now, do magic */ 2409 /* update ev_rt_now, do magic */
2383 time_update (EV_A_ waittime + sleeptime); 2410 time_update (EV_A_ waittime + sleeptime);
2384 } 2411 }
2385 2412
2403 EV_INVOKE_PENDING; 2430 EV_INVOKE_PENDING;
2404 } 2431 }
2405 while (expect_true ( 2432 while (expect_true (
2406 activecnt 2433 activecnt
2407 && !loop_done 2434 && !loop_done
2408 && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) 2435 && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT))
2409 )); 2436 ));
2410 2437
2411 if (loop_done == EVUNLOOP_ONE) 2438 if (loop_done == EVBREAK_ONE)
2412 loop_done = EVUNLOOP_CANCEL; 2439 loop_done = EVBREAK_CANCEL;
2413 2440
2414#if EV_FEATURE_API 2441#if EV_FEATURE_API
2415 --loop_depth; 2442 --loop_depth;
2416#endif 2443#endif
2417} 2444}
2418 2445
2419void 2446void
2420ev_unloop (EV_P_ int how) 2447ev_break (EV_P_ int how)
2421{ 2448{
2422 loop_done = how; 2449 loop_done = how;
2423} 2450}
2424 2451
2425void 2452void
2573 EV_FREQUENT_CHECK; 2600 EV_FREQUENT_CHECK;
2574 2601
2575 wlist_del (&anfds[w->fd].head, (WL)w); 2602 wlist_del (&anfds[w->fd].head, (WL)w);
2576 ev_stop (EV_A_ (W)w); 2603 ev_stop (EV_A_ (W)w);
2577 2604
2578 fd_change (EV_A_ w->fd, 1); 2605 fd_change (EV_A_ w->fd, EV_ANFD_REIFY);
2579 2606
2580 EV_FREQUENT_CHECK; 2607 EV_FREQUENT_CHECK;
2581} 2608}
2582 2609
2583void noinline 2610void noinline
3400 3427
3401#if EV_EMBED_ENABLE 3428#if EV_EMBED_ENABLE
3402void noinline 3429void noinline
3403ev_embed_sweep (EV_P_ ev_embed *w) 3430ev_embed_sweep (EV_P_ ev_embed *w)
3404{ 3431{
3405 ev_loop (w->other, EVLOOP_NONBLOCK); 3432 ev_run (w->other, EVRUN_NOWAIT);
3406} 3433}
3407 3434
3408static void 3435static void
3409embed_io_cb (EV_P_ ev_io *io, int revents) 3436embed_io_cb (EV_P_ ev_io *io, int revents)
3410{ 3437{
3411 ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); 3438 ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io));
3412 3439
3413 if (ev_cb (w)) 3440 if (ev_cb (w))
3414 ev_feed_event (EV_A_ (W)w, EV_EMBED); 3441 ev_feed_event (EV_A_ (W)w, EV_EMBED);
3415 else 3442 else
3416 ev_loop (w->other, EVLOOP_NONBLOCK); 3443 ev_run (w->other, EVRUN_NOWAIT);
3417} 3444}
3418 3445
3419static void 3446static void
3420embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents) 3447embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents)
3421{ 3448{
3425 EV_P = w->other; 3452 EV_P = w->other;
3426 3453
3427 while (fdchangecnt) 3454 while (fdchangecnt)
3428 { 3455 {
3429 fd_reify (EV_A); 3456 fd_reify (EV_A);
3430 ev_loop (EV_A_ EVLOOP_NONBLOCK); 3457 ev_run (EV_A_ EVRUN_NOWAIT);
3431 } 3458 }
3432 } 3459 }
3433} 3460}
3434 3461
3435static void 3462static void
3441 3468
3442 { 3469 {
3443 EV_P = w->other; 3470 EV_P = w->other;
3444 3471
3445 ev_loop_fork (EV_A); 3472 ev_loop_fork (EV_A);
3446 ev_loop (EV_A_ EVLOOP_NONBLOCK); 3473 ev_run (EV_A_ EVRUN_NOWAIT);
3447 } 3474 }
3448 3475
3449 ev_embed_start (EV_A_ w); 3476 ev_embed_start (EV_A_ w);
3450} 3477}
3451 3478
3550ev_async_start (EV_P_ ev_async *w) 3577ev_async_start (EV_P_ ev_async *w)
3551{ 3578{
3552 if (expect_false (ev_is_active (w))) 3579 if (expect_false (ev_is_active (w)))
3553 return; 3580 return;
3554 3581
3582 w->sent = 0;
3583
3555 evpipe_init (EV_A); 3584 evpipe_init (EV_A);
3556 3585
3557 EV_FREQUENT_CHECK; 3586 EV_FREQUENT_CHECK;
3558 3587
3559 ev_start (EV_A_ (W)w, ++asynccnt); 3588 ev_start (EV_A_ (W)w, ++asynccnt);
3636{ 3665{
3637 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 3666 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
3638 3667
3639 if (expect_false (!once)) 3668 if (expect_false (!once))
3640 { 3669 {
3641 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); 3670 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg);
3642 return; 3671 return;
3643 } 3672 }
3644 3673
3645 once->cb = cb; 3674 once->cb = cb;
3646 once->arg = arg; 3675 once->arg = arg;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines