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

Comparing libev/ev.c (file contents):
Revision 1.358 by root, Sun Oct 24 14:44:40 2010 UTC vs.
Revision 1.372 by root, Wed Feb 16 08:02:50 2011 UTC

1/* 1/*
2 * libev event processing core, watcher management 2 * libev event processing core, watcher management
3 * 3 *
4 * Copyright (c) 2007,2008,2009,2010 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libev@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright notice, 10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer. 11 * this list of conditions and the following disclaimer.
12 * 12 *
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution. 15 * documentation and/or other materials provided with the distribution.
16 * 16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
19 * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 20 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
21 * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
376# undef EV_USE_INOTIFY 376# undef EV_USE_INOTIFY
377# define EV_USE_INOTIFY 0 377# define EV_USE_INOTIFY 0
378#endif 378#endif
379 379
380#if !EV_USE_NANOSLEEP 380#if !EV_USE_NANOSLEEP
381# ifndef _WIN32 381/* hp-ux has it in sys/time.h, which we unconditionally include above */
382# if !defined(_WIN32) && !defined(__hpux)
382# include <sys/select.h> 383# include <sys/select.h>
383# endif 384# endif
384#endif 385#endif
385 386
386#if EV_USE_INOTIFY 387#if EV_USE_INOTIFY
530 531
531static unsigned int noinline 532static unsigned int noinline
532ev_linux_version (void) 533ev_linux_version (void)
533{ 534{
534#ifdef __linux 535#ifdef __linux
536 unsigned int v = 0;
535 struct utsname buf; 537 struct utsname buf;
536 unsigned int v;
537 int i; 538 int i;
538 char *p = buf.release; 539 char *p = buf.release;
539 540
540 if (uname (&buf)) 541 if (uname (&buf))
541 return 0; 542 return 0;
591 if (syserr_cb) 592 if (syserr_cb)
592 syserr_cb (msg); 593 syserr_cb (msg);
593 else 594 else
594 { 595 {
595#if EV_AVOID_STDIO 596#if EV_AVOID_STDIO
596 const char *err = strerror (errno);
597
598 ev_printerr (msg); 597 ev_printerr (msg);
599 ev_printerr (": "); 598 ev_printerr (": ");
600 ev_printerr (err); 599 ev_printerr (strerror (errno));
601 ev_printerr ("\n"); 600 ev_printerr ("\n");
602#else 601#else
603 perror (msg); 602 perror (msg);
604#endif 603#endif
605 abort (); 604 abort ();
639 ptr = alloc (ptr, size); 638 ptr = alloc (ptr, size);
640 639
641 if (!ptr && size) 640 if (!ptr && size)
642 { 641 {
643#if EV_AVOID_STDIO 642#if EV_AVOID_STDIO
644 ev_printerr ("libev: memory allocation failed, aborting.\n"); 643 ev_printerr ("(libev) memory allocation failed, aborting.\n");
645#else 644#else
646 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); 645 fprintf (stderr, "(libev) cannot allocate %ld bytes, aborting.", size);
647#endif 646#endif
648 abort (); 647 abort ();
649 } 648 }
650 649
651 return ptr; 650 return ptr;
817 select (0, 0, 0, 0, &tv); 816 select (0, 0, 0, 0, &tv);
818#endif 817#endif
819 } 818 }
820} 819}
821 820
821inline_speed int
822ev_timeout_to_ms (ev_tstamp timeout)
823{
824 int ms = timeout * 1000. + .999999;
825
826 return expect_true (ms) ? ms : timeout < 1e-6 ? 0 : 1;
827}
828
822/*****************************************************************************/ 829/*****************************************************************************/
823 830
824#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ 831#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */
825 832
826/* find a suitable new size for the given array, */ 833/* find a suitable new size for the given array, */
967inline_size void 974inline_size void
968fd_reify (EV_P) 975fd_reify (EV_P)
969{ 976{
970 int i; 977 int i;
971 978
979#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP
980 for (i = 0; i < fdchangecnt; ++i)
981 {
982 int fd = fdchanges [i];
983 ANFD *anfd = anfds + fd;
984
985 if (anfd->reify & EV__IOFDSET)
986 {
987 SOCKET handle = EV_FD_TO_WIN32_HANDLE (fd);
988
989 if (handle != anfd->handle)
990 {
991 unsigned long arg;
992
993 assert (("libev: only socket fds supported in this configuration", ioctlsocket (handle, FIONREAD, &arg) == 0));
994
995 /* handle changed, but fd didn't - we need to do it in two steps */
996 backend_modify (EV_A_ fd, anfd->events, 0);
997 anfd->events = 0;
998 anfd->handle = handle;
999 }
1000 }
1001 }
1002#endif
1003
972 for (i = 0; i < fdchangecnt; ++i) 1004 for (i = 0; i < fdchangecnt; ++i)
973 { 1005 {
974 int fd = fdchanges [i]; 1006 int fd = fdchanges [i];
975 ANFD *anfd = anfds + fd; 1007 ANFD *anfd = anfds + fd;
976 ev_io *w; 1008 ev_io *w;
977 1009
978 unsigned char o_events = anfd->events; 1010 unsigned char o_events = anfd->events;
979 unsigned char o_reify = anfd->reify; 1011 unsigned char o_reify = anfd->reify;
980 1012
981 anfd->reify = 0; 1013 anfd->reify = 0;
982
983#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP
984 if (o_reify & EV__IOFDSET)
985 {
986 unsigned long arg;
987 anfd->handle = EV_FD_TO_WIN32_HANDLE (fd);
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
990 }
991#endif
992 1014
993 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ 1015 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */
994 { 1016 {
995 anfd->events = 0; 1017 anfd->events = 0;
996 1018
1345 char dummy; 1367 char dummy;
1346 /* see discussion in evpipe_write when you think this read should be recv in win32 */ 1368 /* see discussion in evpipe_write when you think this read should be recv in win32 */
1347 read (evpipe [0], &dummy, 1); 1369 read (evpipe [0], &dummy, 1);
1348 } 1370 }
1349 1371
1372#if EV_SIGNAL_ENABLE
1350 if (sig_pending) 1373 if (sig_pending)
1351 { 1374 {
1352 sig_pending = 0; 1375 sig_pending = 0;
1353 1376
1354 for (i = EV_NSIG - 1; i--; ) 1377 for (i = EV_NSIG - 1; i--; )
1355 if (expect_false (signals [i].pending)) 1378 if (expect_false (signals [i].pending))
1356 ev_feed_signal_event (EV_A_ i + 1); 1379 ev_feed_signal_event (EV_A_ i + 1);
1357 } 1380 }
1381#endif
1358 1382
1359#if EV_ASYNC_ENABLE 1383#if EV_ASYNC_ENABLE
1360 if (async_pending) 1384 if (async_pending)
1361 { 1385 {
1362 async_pending = 0; 1386 async_pending = 0;
1371#endif 1395#endif
1372} 1396}
1373 1397
1374/*****************************************************************************/ 1398/*****************************************************************************/
1375 1399
1400void
1401ev_feed_signal (int signum)
1402{
1403#if EV_MULTIPLICITY
1404 EV_P = signals [signum - 1].loop;
1405
1406 if (!EV_A)
1407 return;
1408#endif
1409
1410 signals [signum - 1].pending = 1;
1411 evpipe_write (EV_A_ &sig_pending);
1412}
1413
1376static void 1414static void
1377ev_sighandler (int signum) 1415ev_sighandler (int signum)
1378{ 1416{
1379#if EV_MULTIPLICITY
1380 EV_P = signals [signum - 1].loop;
1381#endif
1382
1383#ifdef _WIN32 1417#ifdef _WIN32
1384 signal (signum, ev_sighandler); 1418 signal (signum, ev_sighandler);
1385#endif 1419#endif
1386 1420
1387 signals [signum - 1].pending = 1; 1421 ev_feed_signal (signum);
1388 evpipe_write (EV_A_ &sig_pending);
1389} 1422}
1390 1423
1391void noinline 1424void noinline
1392ev_feed_signal_event (EV_P_ int signum) 1425ev_feed_signal_event (EV_P_ int signum)
1393{ 1426{
1645static void noinline 1678static void noinline
1646loop_init (EV_P_ unsigned int flags) 1679loop_init (EV_P_ unsigned int flags)
1647{ 1680{
1648 if (!backend) 1681 if (!backend)
1649 { 1682 {
1683 origflags = flags;
1684
1650#if EV_USE_REALTIME 1685#if EV_USE_REALTIME
1651 if (!have_realtime) 1686 if (!have_realtime)
1652 { 1687 {
1653 struct timespec ts; 1688 struct timespec ts;
1654 1689
1699#endif 1734#endif
1700#if EV_USE_SIGNALFD 1735#if EV_USE_SIGNALFD
1701 sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1; 1736 sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1;
1702#endif 1737#endif
1703 1738
1704 if (!(flags & 0x0000ffffU)) 1739 if (!(flags & EVBACKEND_MASK))
1705 flags |= ev_recommended_backends (); 1740 flags |= ev_recommended_backends ();
1706 1741
1707#if EV_USE_IOCP 1742#if EV_USE_IOCP
1708 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); 1743 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags);
1709#endif 1744#endif
1731#endif 1766#endif
1732 } 1767 }
1733} 1768}
1734 1769
1735/* free up a loop structure */ 1770/* free up a loop structure */
1736static void noinline 1771void
1737loop_destroy (EV_P) 1772ev_loop_destroy (EV_P)
1738{ 1773{
1739 int i; 1774 int i;
1775
1776#if EV_MULTIPLICITY
1777 /* mimic free (0) */
1778 if (!EV_A)
1779 return;
1780#endif
1781
1782#if EV_CLEANUP_ENABLE
1783 /* queue cleanup watchers (and execute them) */
1784 if (expect_false (cleanupcnt))
1785 {
1786 queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP);
1787 EV_INVOKE_PENDING;
1788 }
1789#endif
1790
1791#if EV_CHILD_ENABLE
1792 if (ev_is_active (&childev))
1793 {
1794 ev_ref (EV_A); /* child watcher */
1795 ev_signal_stop (EV_A_ &childev);
1796 }
1797#endif
1740 1798
1741 if (ev_is_active (&pipe_w)) 1799 if (ev_is_active (&pipe_w))
1742 { 1800 {
1743 /*ev_ref (EV_A);*/ 1801 /*ev_ref (EV_A);*/
1744 /*ev_io_stop (EV_A_ &pipe_w);*/ 1802 /*ev_io_stop (EV_A_ &pipe_w);*/
1805 array_free (periodic, EMPTY); 1863 array_free (periodic, EMPTY);
1806#endif 1864#endif
1807#if EV_FORK_ENABLE 1865#if EV_FORK_ENABLE
1808 array_free (fork, EMPTY); 1866 array_free (fork, EMPTY);
1809#endif 1867#endif
1868#if EV_CLEANUP_ENABLE
1869 array_free (cleanup, EMPTY);
1870#endif
1810 array_free (prepare, EMPTY); 1871 array_free (prepare, EMPTY);
1811 array_free (check, EMPTY); 1872 array_free (check, EMPTY);
1812#if EV_ASYNC_ENABLE 1873#if EV_ASYNC_ENABLE
1813 array_free (async, EMPTY); 1874 array_free (async, EMPTY);
1814#endif 1875#endif
1815 1876
1816 backend = 0; 1877 backend = 0;
1878
1879#if EV_MULTIPLICITY
1880 if (ev_is_default_loop (EV_A))
1881#endif
1882 ev_default_loop_ptr = 0;
1883#if EV_MULTIPLICITY
1884 else
1885 ev_free (EV_A);
1886#endif
1817} 1887}
1818 1888
1819#if EV_USE_INOTIFY 1889#if EV_USE_INOTIFY
1820inline_size void infy_fork (EV_P); 1890inline_size void infy_fork (EV_P);
1821#endif 1891#endif
1880 loop_init (EV_A_ flags); 1950 loop_init (EV_A_ flags);
1881 1951
1882 if (ev_backend (EV_A)) 1952 if (ev_backend (EV_A))
1883 return EV_A; 1953 return EV_A;
1884 1954
1955 ev_free (EV_A);
1885 return 0; 1956 return 0;
1886} 1957}
1887 1958
1888void
1889ev_loop_destroy (EV_P)
1890{
1891 loop_destroy (EV_A);
1892 ev_free (loop);
1893}
1894
1895void
1896ev_loop_fork (EV_P)
1897{
1898 postfork = 1; /* must be in line with ev_default_fork */
1899}
1900#endif /* multiplicity */ 1959#endif /* multiplicity */
1901 1960
1902#if EV_VERIFY 1961#if EV_VERIFY
1903static void noinline 1962static void noinline
1904verify_watcher (EV_P_ W w) 1963verify_watcher (EV_P_ W w)
1979#if EV_FORK_ENABLE 2038#if EV_FORK_ENABLE
1980 assert (forkmax >= forkcnt); 2039 assert (forkmax >= forkcnt);
1981 array_verify (EV_A_ (W *)forks, forkcnt); 2040 array_verify (EV_A_ (W *)forks, forkcnt);
1982#endif 2041#endif
1983 2042
2043#if EV_CLEANUP_ENABLE
2044 assert (cleanupmax >= cleanupcnt);
2045 array_verify (EV_A_ (W *)cleanups, cleanupcnt);
2046#endif
2047
1984#if EV_ASYNC_ENABLE 2048#if EV_ASYNC_ENABLE
1985 assert (asyncmax >= asynccnt); 2049 assert (asyncmax >= asynccnt);
1986 array_verify (EV_A_ (W *)asyncs, asynccnt); 2050 array_verify (EV_A_ (W *)asyncs, asynccnt);
1987#endif 2051#endif
1988 2052
2038 2102
2039 return ev_default_loop_ptr; 2103 return ev_default_loop_ptr;
2040} 2104}
2041 2105
2042void 2106void
2043ev_default_destroy (void) 2107ev_loop_fork (EV_P)
2044{ 2108{
2045#if EV_MULTIPLICITY
2046 EV_P = ev_default_loop_ptr;
2047#endif
2048
2049 ev_default_loop_ptr = 0;
2050
2051#if EV_CHILD_ENABLE
2052 ev_ref (EV_A); /* child watcher */
2053 ev_signal_stop (EV_A_ &childev);
2054#endif
2055
2056 loop_destroy (EV_A);
2057}
2058
2059void
2060ev_default_fork (void)
2061{
2062#if EV_MULTIPLICITY
2063 EV_P = ev_default_loop_ptr;
2064#endif
2065
2066 postfork = 1; /* must be in line with ev_loop_fork */ 2109 postfork = 1; /* must be in line with ev_default_fork */
2067} 2110}
2068 2111
2069/*****************************************************************************/ 2112/*****************************************************************************/
2070 2113
2071void 2114void
2093 2136
2094 for (pri = NUMPRI; pri--; ) 2137 for (pri = NUMPRI; pri--; )
2095 while (pendingcnt [pri]) 2138 while (pendingcnt [pri])
2096 { 2139 {
2097 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 2140 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
2098
2099 /*assert (("libev: non-pending watcher on pending list", p->w->pending));*/
2100 /* ^ this is no longer true, as pending_w could be here */
2101 2141
2102 p->w->pending = 0; 2142 p->w->pending = 0;
2103 EV_CB_INVOKE (p->w, p->events); 2143 EV_CB_INVOKE (p->w, p->events);
2104 EV_FREQUENT_CHECK; 2144 EV_FREQUENT_CHECK;
2105 } 2145 }
2167 feed_reverse_done (EV_A_ EV_TIMER); 2207 feed_reverse_done (EV_A_ EV_TIMER);
2168 } 2208 }
2169} 2209}
2170 2210
2171#if EV_PERIODIC_ENABLE 2211#if EV_PERIODIC_ENABLE
2212
2213inline_speed void
2214periodic_recalc (EV_P_ ev_periodic *w)
2215{
2216 /* TODO: use slow but potentially more correct incremental algo, */
2217 /* also do not rely on ceil */
2218 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
2219}
2220
2172/* make periodics pending */ 2221/* make periodics pending */
2173inline_size void 2222inline_size void
2174periodics_reify (EV_P) 2223periodics_reify (EV_P)
2175{ 2224{
2176 EV_FREQUENT_CHECK; 2225 EV_FREQUENT_CHECK;
2195 ANHE_at_cache (periodics [HEAP0]); 2244 ANHE_at_cache (periodics [HEAP0]);
2196 downheap (periodics, periodiccnt, HEAP0); 2245 downheap (periodics, periodiccnt, HEAP0);
2197 } 2246 }
2198 else if (w->interval) 2247 else if (w->interval)
2199 { 2248 {
2200 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 2249 periodic_recalc (EV_A_ w);
2250
2201 /* if next trigger time is not sufficiently in the future, put it there */ 2251 /* if next trigger time is not sufficiently in the future, put it there */
2202 /* this might happen because of floating point inexactness */ 2252 /* this might happen because of floating point inexactness */
2203 if (ev_at (w) - ev_rt_now < TIME_EPSILON) 2253 if (ev_at (w) - ev_rt_now < TIME_EPSILON)
2204 { 2254 {
2205 ev_at (w) += w->interval; 2255 ev_at (w) += w->interval;
2239 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [i]); 2289 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [i]);
2240 2290
2241 if (w->reschedule_cb) 2291 if (w->reschedule_cb)
2242 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 2292 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
2243 else if (w->interval) 2293 else if (w->interval)
2244 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 2294 periodic_recalc (EV_A_ w);
2245 2295
2246 ANHE_at_cache (periodics [i]); 2296 ANHE_at_cache (periodics [i]);
2247 } 2297 }
2248 2298
2249 reheap (periodics, periodiccnt); 2299 reheap (periodics, periodiccnt);
2741 if (w->reschedule_cb) 2791 if (w->reschedule_cb)
2742 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 2792 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
2743 else if (w->interval) 2793 else if (w->interval)
2744 { 2794 {
2745 assert (("libev: ev_periodic_start called with negative interval value", w->interval >= 0.)); 2795 assert (("libev: ev_periodic_start called with negative interval value", w->interval >= 0.));
2746 /* this formula differs from the one in periodic_reify because we do not always round up */ 2796 periodic_recalc (EV_A_ w);
2747 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
2748 } 2797 }
2749 else 2798 else
2750 ev_at (w) = w->offset; 2799 ev_at (w) = w->offset;
2751 2800
2752 EV_FREQUENT_CHECK; 2801 EV_FREQUENT_CHECK;
2873 sa.sa_handler = ev_sighandler; 2922 sa.sa_handler = ev_sighandler;
2874 sigfillset (&sa.sa_mask); 2923 sigfillset (&sa.sa_mask);
2875 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ 2924 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */
2876 sigaction (w->signum, &sa, 0); 2925 sigaction (w->signum, &sa, 0);
2877 2926
2927 if (origflags & EVFLAG_NOSIGMASK)
2928 {
2878 sigemptyset (&sa.sa_mask); 2929 sigemptyset (&sa.sa_mask);
2879 sigaddset (&sa.sa_mask, w->signum); 2930 sigaddset (&sa.sa_mask, w->signum);
2880 sigprocmask (SIG_UNBLOCK, &sa.sa_mask, 0); 2931 sigprocmask (SIG_UNBLOCK, &sa.sa_mask, 0);
2932 }
2881#endif 2933#endif
2882 } 2934 }
2883 2935
2884 EV_FREQUENT_CHECK; 2936 EV_FREQUENT_CHECK;
2885} 2937}
3026 if (!pend || pend == path) 3078 if (!pend || pend == path)
3027 break; 3079 break;
3028 3080
3029 *pend = 0; 3081 *pend = 0;
3030 w->wd = inotify_add_watch (fs_fd, path, mask); 3082 w->wd = inotify_add_watch (fs_fd, path, mask);
3031 } 3083 }
3032 while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); 3084 while (w->wd < 0 && (errno == ENOENT || errno == EACCES));
3033 } 3085 }
3034 } 3086 }
3035 3087
3036 if (w->wd >= 0) 3088 if (w->wd >= 0)
3577 3629
3578 EV_FREQUENT_CHECK; 3630 EV_FREQUENT_CHECK;
3579} 3631}
3580#endif 3632#endif
3581 3633
3634#if EV_CLEANUP_ENABLE
3635void
3636ev_cleanup_start (EV_P_ ev_cleanup *w)
3637{
3638 if (expect_false (ev_is_active (w)))
3639 return;
3640
3641 EV_FREQUENT_CHECK;
3642
3643 ev_start (EV_A_ (W)w, ++cleanupcnt);
3644 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2);
3645 cleanups [cleanupcnt - 1] = w;
3646
3647 /* cleanup watchers should never keep a refcount on the loop */
3648 ev_unref (EV_A);
3649 EV_FREQUENT_CHECK;
3650}
3651
3652void
3653ev_cleanup_stop (EV_P_ ev_cleanup *w)
3654{
3655 clear_pending (EV_A_ (W)w);
3656 if (expect_false (!ev_is_active (w)))
3657 return;
3658
3659 EV_FREQUENT_CHECK;
3660 ev_ref (EV_A);
3661
3662 {
3663 int active = ev_active (w);
3664
3665 cleanups [active - 1] = cleanups [--cleanupcnt];
3666 ev_active (cleanups [active - 1]) = active;
3667 }
3668
3669 ev_stop (EV_A_ (W)w);
3670
3671 EV_FREQUENT_CHECK;
3672}
3673#endif
3674
3582#if EV_ASYNC_ENABLE 3675#if EV_ASYNC_ENABLE
3583void 3676void
3584ev_async_start (EV_P_ ev_async *w) 3677ev_async_start (EV_P_ ev_async *w)
3585{ 3678{
3586 if (expect_false (ev_is_active (w))) 3679 if (expect_false (ev_is_active (w)))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines