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

Comparing libev/ev.c (file contents):
Revision 1.352 by root, Thu Oct 21 02:33:08 2010 UTC vs.
Revision 1.363 by root, Sun Oct 24 19:38:20 2010 UTC

35 * and other provisions required by the GPL. If you do not delete the 35 * and other provisions required by the GPL. If you do not delete the
36 * provisions above, a recipient may use your version of this file under 36 * provisions above, a recipient may use your version of this file under
37 * either the BSD or the GPL. 37 * either the BSD or the GPL.
38 */ 38 */
39 39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/* this big block deduces configuration from config.h */ 40/* this big block deduces configuration from config.h */
45#ifndef EV_STANDALONE 41#ifndef EV_STANDALONE
46# ifdef EV_CONFIG_H 42# ifdef EV_CONFIG_H
47# include EV_CONFIG_H 43# include EV_CONFIG_H
48# else 44# else
182# include EV_H 178# include EV_H
183#else 179#else
184# include "ev.h" 180# include "ev.h"
185#endif 181#endif
186 182
183EV_CPP(extern "C" {)
184
187#ifndef _WIN32 185#ifndef _WIN32
188# include <sys/time.h> 186# include <sys/time.h>
189# include <sys/wait.h> 187# include <sys/wait.h>
190# include <unistd.h> 188# include <unistd.h>
191#else 189#else
384# include <sys/select.h> 382# include <sys/select.h>
385# endif 383# endif
386#endif 384#endif
387 385
388#if EV_USE_INOTIFY 386#if EV_USE_INOTIFY
389# include <sys/utsname.h>
390# include <sys/statfs.h> 387# include <sys/statfs.h>
391# include <sys/inotify.h> 388# include <sys/inotify.h>
392/* some very old inotify.h headers don't have IN_DONT_FOLLOW */ 389/* some very old inotify.h headers don't have IN_DONT_FOLLOW */
393# ifndef IN_DONT_FOLLOW 390# ifndef IN_DONT_FOLLOW
394# undef EV_USE_INOTIFY 391# undef EV_USE_INOTIFY
411# define EFD_CLOEXEC O_CLOEXEC 408# define EFD_CLOEXEC O_CLOEXEC
412# else 409# else
413# define EFD_CLOEXEC 02000000 410# define EFD_CLOEXEC 02000000
414# endif 411# endif
415# endif 412# endif
416# ifdef __cplusplus
417extern "C" {
418# endif
419int (eventfd) (unsigned int initval, int flags); 413EV_CPP(extern "C") int (eventfd) (unsigned int initval, int flags);
420# ifdef __cplusplus
421}
422# endif
423#endif 414#endif
424 415
425#if EV_USE_SIGNALFD 416#if EV_USE_SIGNALFD
426/* our minimum requirement is glibc 2.7 which has the stub, but not the header */ 417/* our minimum requirement is glibc 2.7 which has the stub, but not the header */
427# include <stdint.h> 418# include <stdint.h>
433# define SFD_CLOEXEC O_CLOEXEC 424# define SFD_CLOEXEC O_CLOEXEC
434# else 425# else
435# define SFD_CLOEXEC 02000000 426# define SFD_CLOEXEC 02000000
436# endif 427# endif
437# endif 428# endif
438# ifdef __cplusplus
439extern "C" {
440# endif
441int signalfd (int fd, const sigset_t *mask, int flags); 429EV_CPP (extern "C") int signalfd (int fd, const sigset_t *mask, int flags);
442 430
443struct signalfd_siginfo 431struct signalfd_siginfo
444{ 432{
445 uint32_t ssi_signo; 433 uint32_t ssi_signo;
446 char pad[128 - sizeof (uint32_t)]; 434 char pad[128 - sizeof (uint32_t)];
447}; 435};
448# ifdef __cplusplus
449}
450# endif
451#endif 436#endif
452 437
453/**/ 438/**/
454 439
455#if EV_VERIFY >= 3 440#if EV_VERIFY >= 3
537# include "ev_win32.c" 522# include "ev_win32.c"
538#endif 523#endif
539 524
540/*****************************************************************************/ 525/*****************************************************************************/
541 526
527#ifdef __linux
528# include <sys/utsname.h>
529#endif
530
531static unsigned int noinline
532ev_linux_version (void)
533{
534#ifdef __linux
535 unsigned int v = 0;
536 struct utsname buf;
537 int i;
538 char *p = buf.release;
539
540 if (uname (&buf))
541 return 0;
542
543 for (i = 3+1; --i; )
544 {
545 unsigned int c = 0;
546
547 for (;;)
548 {
549 if (*p >= '0' && *p <= '9')
550 c = c * 10 + *p++ - '0';
551 else
552 {
553 p += *p == '.';
554 break;
555 }
556 }
557
558 v = (v << 8) | c;
559 }
560
561 return v;
562#else
563 return 0;
564#endif
565}
566
567/*****************************************************************************/
568
542#if EV_AVOID_STDIO 569#if EV_AVOID_STDIO
543static void noinline 570static void noinline
544ev_printerr (const char *msg) 571ev_printerr (const char *msg)
545{ 572{
546 write (STDERR_FILENO, msg, strlen (msg)); 573 write (STDERR_FILENO, msg, strlen (msg));
641 unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ 668 unsigned char emask; /* the epoll backend stores the actual kernel mask in here */
642 unsigned char unused; 669 unsigned char unused;
643#if EV_USE_EPOLL 670#if EV_USE_EPOLL
644 unsigned int egen; /* generation counter to counter epoll bugs */ 671 unsigned int egen; /* generation counter to counter epoll bugs */
645#endif 672#endif
646#if EV_SELECT_IS_WINSOCKET 673#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP
647 SOCKET handle; 674 SOCKET handle;
675#endif
676#if EV_USE_IOCP
677 OVERLAPPED or, ow;
648#endif 678#endif
649} ANFD; 679} ANFD;
650 680
651/* stores the pending event set for a given watcher */ 681/* stores the pending event set for a given watcher */
652typedef struct 682typedef struct
717# define EV_RELEASE_CB (void)0 747# define EV_RELEASE_CB (void)0
718# define EV_ACQUIRE_CB (void)0 748# define EV_ACQUIRE_CB (void)0
719# define EV_INVOKE_PENDING ev_invoke_pending (EV_A) 749# define EV_INVOKE_PENDING ev_invoke_pending (EV_A)
720#endif 750#endif
721 751
722#define EVUNLOOP_RECURSE 0x80 752#define EVBREAK_RECURSE 0x80
723 753
724/*****************************************************************************/ 754/*****************************************************************************/
725 755
726#ifndef EV_HAVE_EV_TIME 756#ifndef EV_HAVE_EV_TIME
727ev_tstamp 757ev_tstamp
948 unsigned char o_events = anfd->events; 978 unsigned char o_events = anfd->events;
949 unsigned char o_reify = anfd->reify; 979 unsigned char o_reify = anfd->reify;
950 980
951 anfd->reify = 0; 981 anfd->reify = 0;
952 982
953#if EV_SELECT_IS_WINSOCKET 983#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP
954 if (o_reify & EV__IOFDSET) 984 if (o_reify & EV__IOFDSET)
955 { 985 {
956 unsigned long arg; 986 unsigned long arg;
957 anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); 987 anfd->handle = EV_FD_TO_WIN32_HANDLE (fd);
958 assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); 988 assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0));
989 printf ("oi %d %x\n", fd, anfd->handle);//D
959 } 990 }
960#endif 991#endif
961 992
962 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ 993 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */
963 { 994 {
1462 1493
1463#endif 1494#endif
1464 1495
1465/*****************************************************************************/ 1496/*****************************************************************************/
1466 1497
1498#if EV_USE_IOCP
1499# include "ev_iocp.c"
1500#endif
1467#if EV_USE_PORT 1501#if EV_USE_PORT
1468# include "ev_port.c" 1502# include "ev_port.c"
1469#endif 1503#endif
1470#if EV_USE_KQUEUE 1504#if EV_USE_KQUEUE
1471# include "ev_kqueue.c" 1505# include "ev_kqueue.c"
1544ev_embeddable_backends (void) 1578ev_embeddable_backends (void)
1545{ 1579{
1546 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; 1580 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT;
1547 1581
1548 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ 1582 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */
1549 /* please fix it and tell me how to detect the fix */ 1583 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */
1550 flags &= ~EVBACKEND_EPOLL; 1584 flags &= ~EVBACKEND_EPOLL;
1551 1585
1552 return flags; 1586 return flags;
1553} 1587}
1554 1588
1555unsigned int 1589unsigned int
1668#endif 1702#endif
1669 1703
1670 if (!(flags & 0x0000ffffU)) 1704 if (!(flags & 0x0000ffffU))
1671 flags |= ev_recommended_backends (); 1705 flags |= ev_recommended_backends ();
1672 1706
1707#if EV_USE_IOCP
1708 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags);
1709#endif
1673#if EV_USE_PORT 1710#if EV_USE_PORT
1674 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); 1711 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags);
1675#endif 1712#endif
1676#if EV_USE_KQUEUE 1713#if EV_USE_KQUEUE
1677 if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); 1714 if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags);
1694#endif 1731#endif
1695 } 1732 }
1696} 1733}
1697 1734
1698/* free up a loop structure */ 1735/* free up a loop structure */
1699static void noinline 1736void
1700loop_destroy (EV_P) 1737ev_loop_destroy (EV_P)
1701{ 1738{
1702 int i; 1739 int i;
1740
1741 /* mimic free (0) */
1742 if (!EV_A)
1743 return;
1744
1745#if EV_CLEANUP_ENABLE
1746 /* queue cleanup watchers (and execute them) */
1747 if (expect_false (cleanupcnt))
1748 {
1749 queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP);
1750 EV_INVOKE_PENDING;
1751 }
1752#endif
1753
1754#if EV_CHILD_ENABLE
1755 if (ev_is_active (&childev))
1756 {
1757 ev_ref (EV_A); /* child watcher */
1758 ev_signal_stop (EV_A_ &childev);
1759 }
1760#endif
1703 1761
1704 if (ev_is_active (&pipe_w)) 1762 if (ev_is_active (&pipe_w))
1705 { 1763 {
1706 /*ev_ref (EV_A);*/ 1764 /*ev_ref (EV_A);*/
1707 /*ev_io_stop (EV_A_ &pipe_w);*/ 1765 /*ev_io_stop (EV_A_ &pipe_w);*/
1729#endif 1787#endif
1730 1788
1731 if (backend_fd >= 0) 1789 if (backend_fd >= 0)
1732 close (backend_fd); 1790 close (backend_fd);
1733 1791
1792#if EV_USE_IOCP
1793 if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A);
1794#endif
1734#if EV_USE_PORT 1795#if EV_USE_PORT
1735 if (backend == EVBACKEND_PORT ) port_destroy (EV_A); 1796 if (backend == EVBACKEND_PORT ) port_destroy (EV_A);
1736#endif 1797#endif
1737#if EV_USE_KQUEUE 1798#if EV_USE_KQUEUE
1738 if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); 1799 if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A);
1765 array_free (periodic, EMPTY); 1826 array_free (periodic, EMPTY);
1766#endif 1827#endif
1767#if EV_FORK_ENABLE 1828#if EV_FORK_ENABLE
1768 array_free (fork, EMPTY); 1829 array_free (fork, EMPTY);
1769#endif 1830#endif
1831#if EV_CLEANUP_ENABLE
1832 array_free (cleanup, EMPTY);
1833#endif
1770 array_free (prepare, EMPTY); 1834 array_free (prepare, EMPTY);
1771 array_free (check, EMPTY); 1835 array_free (check, EMPTY);
1772#if EV_ASYNC_ENABLE 1836#if EV_ASYNC_ENABLE
1773 array_free (async, EMPTY); 1837 array_free (async, EMPTY);
1774#endif 1838#endif
1775 1839
1776 backend = 0; 1840 backend = 0;
1841
1842#if EV_MULTIPLICITY
1843 if (ev_is_default_loop (EV_A))
1844#endif
1845 ev_default_loop_ptr = 0;
1846#if EV_MULTIPLICITY
1847 else
1848 ev_free (EV_A);
1849#endif
1777} 1850}
1778 1851
1779#if EV_USE_INOTIFY 1852#if EV_USE_INOTIFY
1780inline_size void infy_fork (EV_P); 1853inline_size void infy_fork (EV_P);
1781#endif 1854#endif
1840 loop_init (EV_A_ flags); 1913 loop_init (EV_A_ flags);
1841 1914
1842 if (ev_backend (EV_A)) 1915 if (ev_backend (EV_A))
1843 return EV_A; 1916 return EV_A;
1844 1917
1918 ev_free (EV_A);
1845 return 0; 1919 return 0;
1846} 1920}
1847 1921
1848void
1849ev_loop_destroy (EV_P)
1850{
1851 loop_destroy (EV_A);
1852 ev_free (loop);
1853}
1854
1855void
1856ev_loop_fork (EV_P)
1857{
1858 postfork = 1; /* must be in line with ev_default_fork */
1859}
1860#endif /* multiplicity */ 1922#endif /* multiplicity */
1861 1923
1862#if EV_VERIFY 1924#if EV_VERIFY
1863static void noinline 1925static void noinline
1864verify_watcher (EV_P_ W w) 1926verify_watcher (EV_P_ W w)
1939#if EV_FORK_ENABLE 2001#if EV_FORK_ENABLE
1940 assert (forkmax >= forkcnt); 2002 assert (forkmax >= forkcnt);
1941 array_verify (EV_A_ (W *)forks, forkcnt); 2003 array_verify (EV_A_ (W *)forks, forkcnt);
1942#endif 2004#endif
1943 2005
2006#if EV_CLEANUP_ENABLE
2007 assert (cleanupmax >= cleanupcnt);
2008 array_verify (EV_A_ (W *)cleanups, cleanupcnt);
2009#endif
2010
1944#if EV_ASYNC_ENABLE 2011#if EV_ASYNC_ENABLE
1945 assert (asyncmax >= asynccnt); 2012 assert (asyncmax >= asynccnt);
1946 array_verify (EV_A_ (W *)asyncs, asynccnt); 2013 array_verify (EV_A_ (W *)asyncs, asynccnt);
1947#endif 2014#endif
1948 2015
1966} 2033}
1967#endif 2034#endif
1968 2035
1969#if EV_MULTIPLICITY 2036#if EV_MULTIPLICITY
1970struct ev_loop * 2037struct ev_loop *
1971ev_default_loop_init (unsigned int flags)
1972#else 2038#else
1973int 2039int
2040#endif
1974ev_default_loop (unsigned int flags) 2041ev_default_loop (unsigned int flags)
1975#endif
1976{ 2042{
1977 if (!ev_default_loop_ptr) 2043 if (!ev_default_loop_ptr)
1978 { 2044 {
1979#if EV_MULTIPLICITY 2045#if EV_MULTIPLICITY
1980 EV_P = ev_default_loop_ptr = &default_loop_struct; 2046 EV_P = ev_default_loop_ptr = &default_loop_struct;
1999 2065
2000 return ev_default_loop_ptr; 2066 return ev_default_loop_ptr;
2001} 2067}
2002 2068
2003void 2069void
2004ev_default_destroy (void) 2070ev_loop_fork (EV_P)
2005{ 2071{
2006#if EV_MULTIPLICITY
2007 EV_P = ev_default_loop_ptr;
2008#endif
2009
2010 ev_default_loop_ptr = 0;
2011
2012#if EV_CHILD_ENABLE
2013 ev_ref (EV_A); /* child watcher */
2014 ev_signal_stop (EV_A_ &childev);
2015#endif
2016
2017 loop_destroy (EV_A);
2018}
2019
2020void
2021ev_default_fork (void)
2022{
2023#if EV_MULTIPLICITY
2024 EV_P = ev_default_loop_ptr;
2025#endif
2026
2027 postfork = 1; /* must be in line with ev_loop_fork */ 2072 postfork = 1; /* must be in line with ev_default_fork */
2028} 2073}
2029 2074
2030/*****************************************************************************/ 2075/*****************************************************************************/
2031 2076
2032void 2077void
2292 mn_now = ev_rt_now; 2337 mn_now = ev_rt_now;
2293 } 2338 }
2294} 2339}
2295 2340
2296void 2341void
2297ev_loop (EV_P_ int flags) 2342ev_run (EV_P_ int flags)
2298{ 2343{
2299#if EV_FEATURE_API 2344#if EV_FEATURE_API
2300 ++loop_depth; 2345 ++loop_depth;
2301#endif 2346#endif
2302 2347
2303 assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); 2348 assert (("libev: ev_loop recursion during release detected", loop_done != EVBREAK_RECURSE));
2304 2349
2305 loop_done = EVUNLOOP_CANCEL; 2350 loop_done = EVBREAK_CANCEL;
2306 2351
2307 EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ 2352 EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */
2308 2353
2309 do 2354 do
2310 { 2355 {
2353 /* calculate blocking time */ 2398 /* calculate blocking time */
2354 { 2399 {
2355 ev_tstamp waittime = 0.; 2400 ev_tstamp waittime = 0.;
2356 ev_tstamp sleeptime = 0.; 2401 ev_tstamp sleeptime = 0.;
2357 2402
2403 /* remember old timestamp for io_blocktime calculation */
2404 ev_tstamp prev_mn_now = mn_now;
2405
2406 /* update time to cancel out callback processing overhead */
2407 time_update (EV_A_ 1e100);
2408
2358 if (expect_true (!(flags & EVLOOP_NONBLOCK || idleall || !activecnt))) 2409 if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt)))
2359 { 2410 {
2360 /* remember old timestamp for io_blocktime calculation */
2361 ev_tstamp prev_mn_now = mn_now;
2362
2363 /* update time to cancel out callback processing overhead */
2364 time_update (EV_A_ 1e100);
2365
2366 waittime = MAX_BLOCKTIME; 2411 waittime = MAX_BLOCKTIME;
2367 2412
2368 if (timercnt) 2413 if (timercnt)
2369 { 2414 {
2370 ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now + backend_fudge; 2415 ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now + backend_fudge;
2400 } 2445 }
2401 2446
2402#if EV_FEATURE_API 2447#if EV_FEATURE_API
2403 ++loop_count; 2448 ++loop_count;
2404#endif 2449#endif
2405 assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ 2450 assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */
2406 backend_poll (EV_A_ waittime); 2451 backend_poll (EV_A_ waittime);
2407 assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ 2452 assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */
2408 2453
2409 /* update ev_rt_now, do magic */ 2454 /* update ev_rt_now, do magic */
2410 time_update (EV_A_ waittime + sleeptime); 2455 time_update (EV_A_ waittime + sleeptime);
2411 } 2456 }
2412 2457
2430 EV_INVOKE_PENDING; 2475 EV_INVOKE_PENDING;
2431 } 2476 }
2432 while (expect_true ( 2477 while (expect_true (
2433 activecnt 2478 activecnt
2434 && !loop_done 2479 && !loop_done
2435 && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) 2480 && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT))
2436 )); 2481 ));
2437 2482
2438 if (loop_done == EVUNLOOP_ONE) 2483 if (loop_done == EVBREAK_ONE)
2439 loop_done = EVUNLOOP_CANCEL; 2484 loop_done = EVBREAK_CANCEL;
2440 2485
2441#if EV_FEATURE_API 2486#if EV_FEATURE_API
2442 --loop_depth; 2487 --loop_depth;
2443#endif 2488#endif
2444} 2489}
2445 2490
2446void 2491void
2447ev_unloop (EV_P_ int how) 2492ev_break (EV_P_ int how)
2448{ 2493{
2449 loop_done = how; 2494 loop_done = how;
2450} 2495}
2451 2496
2452void 2497void
3062 { 3107 {
3063 struct inotify_event *ev = (struct inotify_event *)(buf + ofs); 3108 struct inotify_event *ev = (struct inotify_event *)(buf + ofs);
3064 infy_wd (EV_A_ ev->wd, ev->wd, ev); 3109 infy_wd (EV_A_ ev->wd, ev->wd, ev);
3065 ofs += sizeof (struct inotify_event) + ev->len; 3110 ofs += sizeof (struct inotify_event) + ev->len;
3066 } 3111 }
3067}
3068
3069inline_size unsigned int
3070ev_linux_version (void)
3071{
3072 struct utsname buf;
3073 unsigned int v;
3074 int i;
3075 char *p = buf.release;
3076
3077 if (uname (&buf))
3078 return 0;
3079
3080 for (i = 3+1; --i; )
3081 {
3082 unsigned int c = 0;
3083
3084 for (;;)
3085 {
3086 if (*p >= '0' && *p <= '9')
3087 c = c * 10 + *p++ - '0';
3088 else
3089 {
3090 p += *p == '.';
3091 break;
3092 }
3093 }
3094
3095 v = (v << 8) | c;
3096 }
3097
3098 return v;
3099} 3112}
3100 3113
3101inline_size void 3114inline_size void
3102ev_check_2625 (EV_P) 3115ev_check_2625 (EV_P)
3103{ 3116{
3427 3440
3428#if EV_EMBED_ENABLE 3441#if EV_EMBED_ENABLE
3429void noinline 3442void noinline
3430ev_embed_sweep (EV_P_ ev_embed *w) 3443ev_embed_sweep (EV_P_ ev_embed *w)
3431{ 3444{
3432 ev_loop (w->other, EVLOOP_NONBLOCK); 3445 ev_run (w->other, EVRUN_NOWAIT);
3433} 3446}
3434 3447
3435static void 3448static void
3436embed_io_cb (EV_P_ ev_io *io, int revents) 3449embed_io_cb (EV_P_ ev_io *io, int revents)
3437{ 3450{
3438 ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); 3451 ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io));
3439 3452
3440 if (ev_cb (w)) 3453 if (ev_cb (w))
3441 ev_feed_event (EV_A_ (W)w, EV_EMBED); 3454 ev_feed_event (EV_A_ (W)w, EV_EMBED);
3442 else 3455 else
3443 ev_loop (w->other, EVLOOP_NONBLOCK); 3456 ev_run (w->other, EVRUN_NOWAIT);
3444} 3457}
3445 3458
3446static void 3459static void
3447embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents) 3460embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents)
3448{ 3461{
3452 EV_P = w->other; 3465 EV_P = w->other;
3453 3466
3454 while (fdchangecnt) 3467 while (fdchangecnt)
3455 { 3468 {
3456 fd_reify (EV_A); 3469 fd_reify (EV_A);
3457 ev_loop (EV_A_ EVLOOP_NONBLOCK); 3470 ev_run (EV_A_ EVRUN_NOWAIT);
3458 } 3471 }
3459 } 3472 }
3460} 3473}
3461 3474
3462static void 3475static void
3468 3481
3469 { 3482 {
3470 EV_P = w->other; 3483 EV_P = w->other;
3471 3484
3472 ev_loop_fork (EV_A); 3485 ev_loop_fork (EV_A);
3473 ev_loop (EV_A_ EVLOOP_NONBLOCK); 3486 ev_run (EV_A_ EVRUN_NOWAIT);
3474 } 3487 }
3475 3488
3476 ev_embed_start (EV_A_ w); 3489 ev_embed_start (EV_A_ w);
3477} 3490}
3478 3491
3562 { 3575 {
3563 int active = ev_active (w); 3576 int active = ev_active (w);
3564 3577
3565 forks [active - 1] = forks [--forkcnt]; 3578 forks [active - 1] = forks [--forkcnt];
3566 ev_active (forks [active - 1]) = active; 3579 ev_active (forks [active - 1]) = active;
3580 }
3581
3582 ev_stop (EV_A_ (W)w);
3583
3584 EV_FREQUENT_CHECK;
3585}
3586#endif
3587
3588#if EV_CLEANUP_ENABLE
3589void
3590ev_cleanup_start (EV_P_ ev_cleanup *w)
3591{
3592 if (expect_false (ev_is_active (w)))
3593 return;
3594
3595 EV_FREQUENT_CHECK;
3596
3597 ev_start (EV_A_ (W)w, ++cleanupcnt);
3598 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2);
3599 cleanups [cleanupcnt - 1] = w;
3600
3601 /* cleanup watchers should never keep a refcount on the loop */
3602 ev_unref (EV_A);
3603 EV_FREQUENT_CHECK;
3604}
3605
3606void
3607ev_cleanup_stop (EV_P_ ev_cleanup *w)
3608{
3609 clear_pending (EV_A_ (W)w);
3610 if (expect_false (!ev_is_active (w)))
3611 return;
3612
3613 EV_FREQUENT_CHECK;
3614 ev_ref (EV_A);
3615
3616 {
3617 int active = ev_active (w);
3618
3619 cleanups [active - 1] = cleanups [--cleanupcnt];
3620 ev_active (cleanups [active - 1]) = active;
3567 } 3621 }
3568 3622
3569 ev_stop (EV_A_ (W)w); 3623 ev_stop (EV_A_ (W)w);
3570 3624
3571 EV_FREQUENT_CHECK; 3625 EV_FREQUENT_CHECK;
3807 3861
3808#if EV_MULTIPLICITY 3862#if EV_MULTIPLICITY
3809 #include "ev_wrap.h" 3863 #include "ev_wrap.h"
3810#endif 3864#endif
3811 3865
3812#ifdef __cplusplus 3866EV_CPP(})
3813}
3814#endif
3815 3867

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines