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

Comparing libev/ev.c (file contents):
Revision 1.418 by root, Mon Apr 2 23:14:41 2012 UTC vs.
Revision 1.428 by root, Tue May 8 15:44:09 2012 UTC

202# include <unistd.h> 202# include <unistd.h>
203#else 203#else
204# include <io.h> 204# include <io.h>
205# define WIN32_LEAN_AND_MEAN 205# define WIN32_LEAN_AND_MEAN
206# include <windows.h> 206# include <windows.h>
207# include <winsock2.h>
207# ifndef EV_SELECT_IS_WINSOCKET 208# ifndef EV_SELECT_IS_WINSOCKET
208# define EV_SELECT_IS_WINSOCKET 1 209# define EV_SELECT_IS_WINSOCKET 1
209# endif 210# endif
210# undef EV_AVOID_STDIO 211# undef EV_AVOID_STDIO
211#endif 212#endif
359#endif 360#endif
360 361
361/* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ 362/* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */
362/* which makes programs even slower. might work on other unices, too. */ 363/* which makes programs even slower. might work on other unices, too. */
363#if EV_USE_CLOCK_SYSCALL 364#if EV_USE_CLOCK_SYSCALL
364# include <syscall.h> 365# include <sys/syscall.h>
365# ifdef SYS_clock_gettime 366# ifdef SYS_clock_gettime
366# define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) 367# define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts))
367# undef EV_USE_MONOTONIC 368# undef EV_USE_MONOTONIC
368# define EV_USE_MONOTONIC 1 369# define EV_USE_MONOTONIC 1
369# else 370# else
579 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") 580 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore")
580 #elif defined __s390__ || defined __s390x__ 581 #elif defined __s390__ || defined __s390x__
581 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") 582 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory")
582 #elif defined __mips__ 583 #elif defined __mips__
583 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 584 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
585 #elif defined __alpha__
586 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mb" : : : "memory")
584 #endif 587 #endif
585 #endif 588 #endif
586#endif 589#endif
587 590
588#ifndef ECB_MEMORY_FENCE 591#ifndef ECB_MEMORY_FENCE
1103{ 1106{
1104 write (STDERR_FILENO, msg, strlen (msg)); 1107 write (STDERR_FILENO, msg, strlen (msg));
1105} 1108}
1106#endif 1109#endif
1107 1110
1108static void (*syserr_cb)(const char *msg); 1111static void (*syserr_cb)(const char *msg) EV_THROW;
1109 1112
1110void ecb_cold 1113void ecb_cold
1111ev_set_syserr_cb (void (*cb)(const char *msg)) 1114ev_set_syserr_cb (void (*cb)(const char *msg)) EV_THROW
1112{ 1115{
1113 syserr_cb = cb; 1116 syserr_cb = cb;
1114} 1117}
1115 1118
1116static void noinline ecb_cold 1119static void noinline ecb_cold
1152 free (ptr); 1155 free (ptr);
1153 return 0; 1156 return 0;
1154#endif 1157#endif
1155} 1158}
1156 1159
1157static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; 1160static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul;
1158 1161
1159void ecb_cold 1162void ecb_cold
1160ev_set_allocator (void *(*cb)(void *ptr, long size)) 1163ev_set_allocator (void *(*cb)(void *ptr, long size)) EV_THROW
1161{ 1164{
1162 alloc = cb; 1165 alloc = cb;
1163} 1166}
1164 1167
1165inline_speed void * 1168inline_speed void *
1282 1285
1283/*****************************************************************************/ 1286/*****************************************************************************/
1284 1287
1285#ifndef EV_HAVE_EV_TIME 1288#ifndef EV_HAVE_EV_TIME
1286ev_tstamp 1289ev_tstamp
1287ev_time (void) 1290ev_time (void) EV_THROW
1288{ 1291{
1289#if EV_USE_REALTIME 1292#if EV_USE_REALTIME
1290 if (expect_true (have_realtime)) 1293 if (expect_true (have_realtime))
1291 { 1294 {
1292 struct timespec ts; 1295 struct timespec ts;
1316 return ev_time (); 1319 return ev_time ();
1317} 1320}
1318 1321
1319#if EV_MULTIPLICITY 1322#if EV_MULTIPLICITY
1320ev_tstamp 1323ev_tstamp
1321ev_now (EV_P) 1324ev_now (EV_P) EV_THROW
1322{ 1325{
1323 return ev_rt_now; 1326 return ev_rt_now;
1324} 1327}
1325#endif 1328#endif
1326 1329
1327void 1330void
1328ev_sleep (ev_tstamp delay) 1331ev_sleep (ev_tstamp delay) EV_THROW
1329{ 1332{
1330 if (delay > 0.) 1333 if (delay > 0.)
1331 { 1334 {
1332#if EV_USE_NANOSLEEP 1335#if EV_USE_NANOSLEEP
1333 struct timespec ts; 1336 struct timespec ts;
1414pendingcb (EV_P_ ev_prepare *w, int revents) 1417pendingcb (EV_P_ ev_prepare *w, int revents)
1415{ 1418{
1416} 1419}
1417 1420
1418void noinline 1421void noinline
1419ev_feed_event (EV_P_ void *w, int revents) 1422ev_feed_event (EV_P_ void *w, int revents) EV_THROW
1420{ 1423{
1421 W w_ = (W)w; 1424 W w_ = (W)w;
1422 int pri = ABSPRI (w_); 1425 int pri = ABSPRI (w_);
1423 1426
1424 if (expect_false (w_->pending)) 1427 if (expect_false (w_->pending))
1428 w_->pending = ++pendingcnt [pri]; 1431 w_->pending = ++pendingcnt [pri];
1429 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); 1432 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2);
1430 pendings [pri][w_->pending - 1].w = w_; 1433 pendings [pri][w_->pending - 1].w = w_;
1431 pendings [pri][w_->pending - 1].events = revents; 1434 pendings [pri][w_->pending - 1].events = revents;
1432 } 1435 }
1436
1437 pendingpri = NUMPRI - 1;
1433} 1438}
1434 1439
1435inline_speed void 1440inline_speed void
1436feed_reverse (EV_P_ W w) 1441feed_reverse (EV_P_ W w)
1437{ 1442{
1483 if (expect_true (!anfd->reify)) 1488 if (expect_true (!anfd->reify))
1484 fd_event_nocheck (EV_A_ fd, revents); 1489 fd_event_nocheck (EV_A_ fd, revents);
1485} 1490}
1486 1491
1487void 1492void
1488ev_feed_fd_event (EV_P_ int fd, int revents) 1493ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW
1489{ 1494{
1490 if (fd >= 0 && fd < anfdmax) 1495 if (fd >= 0 && fd < anfdmax)
1491 fd_event_nocheck (EV_A_ fd, revents); 1496 fd_event_nocheck (EV_A_ fd, revents);
1492} 1497}
1493 1498
1842} 1847}
1843 1848
1844inline_speed void 1849inline_speed void
1845evpipe_write (EV_P_ EV_ATOMIC_T *flag) 1850evpipe_write (EV_P_ EV_ATOMIC_T *flag)
1846{ 1851{
1852 ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */
1853
1847 if (expect_true (*flag)) 1854 if (expect_true (*flag))
1848 return; 1855 return;
1849 1856
1850 *flag = 1; 1857 *flag = 1;
1851 1858
1870 write (evfd, &counter, sizeof (uint64_t)); 1877 write (evfd, &counter, sizeof (uint64_t));
1871 } 1878 }
1872 else 1879 else
1873#endif 1880#endif
1874 { 1881 {
1875 /* win32 people keep sending patches that change this write() to send() */ 1882#ifdef _WIN32
1876 /* and then run away. but send() is wrong, it wants a socket handle on win32 */ 1883 WSABUF buf;
1877 /* so when you think this write should be a send instead, please find out */ 1884 DWORD sent;
1878 /* where your send() is from - it's definitely not the microsoft send, and */ 1885 buf.buf = &buf;
1879 /* tell me. thank you. */ 1886 buf.len = 1;
1880 /* it might be that your problem is that your environment needs EV_USE_WSASOCKET */ 1887 WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0);
1881 /* check the ev documentation on how to use this flag */ 1888#else
1882 write (evpipe [1], &(evpipe [1]), 1); 1889 write (evpipe [1], &(evpipe [1]), 1);
1890#endif
1883 } 1891 }
1884 1892
1885 errno = old_errno; 1893 errno = old_errno;
1886 } 1894 }
1887} 1895}
1902 read (evfd, &counter, sizeof (uint64_t)); 1910 read (evfd, &counter, sizeof (uint64_t));
1903 } 1911 }
1904 else 1912 else
1905#endif 1913#endif
1906 { 1914 {
1907 char dummy; 1915 char dummy[4];
1908 /* see discussion in evpipe_write when you think this read should be recv in win32 */ 1916#ifdef _WIN32
1917 WSABUF buf;
1918 DWORD recvd;
1919 buf.buf = dummy;
1920 buf.len = sizeof (dummy);
1921 WSARecv (EV_FD_TO_WIN32_HANDLE (evpipe [0]), &buf, 1, &recvd, 0, 0, 0);
1922#else
1909 read (evpipe [0], &dummy, 1); 1923 read (evpipe [0], &dummy, sizeof (dummy));
1924#endif
1910 } 1925 }
1911 } 1926 }
1912 1927
1913 pipe_write_skipped = 0; 1928 pipe_write_skipped = 0;
1929
1930 ECB_MEMORY_FENCE; /* push out skipped, acquire flags */
1914 1931
1915#if EV_SIGNAL_ENABLE 1932#if EV_SIGNAL_ENABLE
1916 if (sig_pending) 1933 if (sig_pending)
1917 { 1934 {
1918 sig_pending = 0; 1935 sig_pending = 0;
1936
1937 ECB_MEMORY_FENCE_RELEASE;
1919 1938
1920 for (i = EV_NSIG - 1; i--; ) 1939 for (i = EV_NSIG - 1; i--; )
1921 if (expect_false (signals [i].pending)) 1940 if (expect_false (signals [i].pending))
1922 ev_feed_signal_event (EV_A_ i + 1); 1941 ev_feed_signal_event (EV_A_ i + 1);
1923 } 1942 }
1925 1944
1926#if EV_ASYNC_ENABLE 1945#if EV_ASYNC_ENABLE
1927 if (async_pending) 1946 if (async_pending)
1928 { 1947 {
1929 async_pending = 0; 1948 async_pending = 0;
1949
1950 ECB_MEMORY_FENCE_RELEASE;
1930 1951
1931 for (i = asynccnt; i--; ) 1952 for (i = asynccnt; i--; )
1932 if (asyncs [i]->sent) 1953 if (asyncs [i]->sent)
1933 { 1954 {
1934 asyncs [i]->sent = 0; 1955 asyncs [i]->sent = 0;
1939} 1960}
1940 1961
1941/*****************************************************************************/ 1962/*****************************************************************************/
1942 1963
1943void 1964void
1944ev_feed_signal (int signum) 1965ev_feed_signal (int signum) EV_THROW
1945{ 1966{
1946#if EV_MULTIPLICITY 1967#if EV_MULTIPLICITY
1947 EV_P = signals [signum - 1].loop; 1968 EV_P = signals [signum - 1].loop;
1948 1969
1949 if (!EV_A) 1970 if (!EV_A)
1966 1987
1967 ev_feed_signal (signum); 1988 ev_feed_signal (signum);
1968} 1989}
1969 1990
1970void noinline 1991void noinline
1971ev_feed_signal_event (EV_P_ int signum) 1992ev_feed_signal_event (EV_P_ int signum) EV_THROW
1972{ 1993{
1973 WL w; 1994 WL w;
1974 1995
1975 if (expect_false (signum <= 0 || signum > EV_NSIG)) 1996 if (expect_false (signum <= 0 || signum > EV_NSIG))
1976 return; 1997 return;
2092#if EV_USE_SELECT 2113#if EV_USE_SELECT
2093# include "ev_select.c" 2114# include "ev_select.c"
2094#endif 2115#endif
2095 2116
2096int ecb_cold 2117int ecb_cold
2097ev_version_major (void) 2118ev_version_major (void) EV_THROW
2098{ 2119{
2099 return EV_VERSION_MAJOR; 2120 return EV_VERSION_MAJOR;
2100} 2121}
2101 2122
2102int ecb_cold 2123int ecb_cold
2103ev_version_minor (void) 2124ev_version_minor (void) EV_THROW
2104{ 2125{
2105 return EV_VERSION_MINOR; 2126 return EV_VERSION_MINOR;
2106} 2127}
2107 2128
2108/* return true if we are running with elevated privileges and should ignore env variables */ 2129/* return true if we are running with elevated privileges and should ignore env variables */
2116 || getgid () != getegid (); 2137 || getgid () != getegid ();
2117#endif 2138#endif
2118} 2139}
2119 2140
2120unsigned int ecb_cold 2141unsigned int ecb_cold
2121ev_supported_backends (void) 2142ev_supported_backends (void) EV_THROW
2122{ 2143{
2123 unsigned int flags = 0; 2144 unsigned int flags = 0;
2124 2145
2125 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 2146 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
2126 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; 2147 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE;
2130 2151
2131 return flags; 2152 return flags;
2132} 2153}
2133 2154
2134unsigned int ecb_cold 2155unsigned int ecb_cold
2135ev_recommended_backends (void) 2156ev_recommended_backends (void) EV_THROW
2136{ 2157{
2137 unsigned int flags = ev_supported_backends (); 2158 unsigned int flags = ev_supported_backends ();
2138 2159
2139#ifndef __NetBSD__ 2160#ifndef __NetBSD__
2140 /* kqueue is borked on everything but netbsd apparently */ 2161 /* kqueue is borked on everything but netbsd apparently */
2152 2173
2153 return flags; 2174 return flags;
2154} 2175}
2155 2176
2156unsigned int ecb_cold 2177unsigned int ecb_cold
2157ev_embeddable_backends (void) 2178ev_embeddable_backends (void) EV_THROW
2158{ 2179{
2159 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; 2180 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT;
2160 2181
2161 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ 2182 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */
2162 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ 2183 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */
2164 2185
2165 return flags; 2186 return flags;
2166} 2187}
2167 2188
2168unsigned int 2189unsigned int
2169ev_backend (EV_P) 2190ev_backend (EV_P) EV_THROW
2170{ 2191{
2171 return backend; 2192 return backend;
2172} 2193}
2173 2194
2174#if EV_FEATURE_API 2195#if EV_FEATURE_API
2175unsigned int 2196unsigned int
2176ev_iteration (EV_P) 2197ev_iteration (EV_P) EV_THROW
2177{ 2198{
2178 return loop_count; 2199 return loop_count;
2179} 2200}
2180 2201
2181unsigned int 2202unsigned int
2182ev_depth (EV_P) 2203ev_depth (EV_P) EV_THROW
2183{ 2204{
2184 return loop_depth; 2205 return loop_depth;
2185} 2206}
2186 2207
2187void 2208void
2188ev_set_io_collect_interval (EV_P_ ev_tstamp interval) 2209ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW
2189{ 2210{
2190 io_blocktime = interval; 2211 io_blocktime = interval;
2191} 2212}
2192 2213
2193void 2214void
2194ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) 2215ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW
2195{ 2216{
2196 timeout_blocktime = interval; 2217 timeout_blocktime = interval;
2197} 2218}
2198 2219
2199void 2220void
2200ev_set_userdata (EV_P_ void *data) 2221ev_set_userdata (EV_P_ void *data) EV_THROW
2201{ 2222{
2202 userdata = data; 2223 userdata = data;
2203} 2224}
2204 2225
2205void * 2226void *
2206ev_userdata (EV_P) 2227ev_userdata (EV_P) EV_THROW
2207{ 2228{
2208 return userdata; 2229 return userdata;
2209} 2230}
2210 2231
2211void 2232void
2212ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) 2233ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) EV_THROW
2213{ 2234{
2214 invoke_cb = invoke_pending_cb; 2235 invoke_cb = invoke_pending_cb;
2215} 2236}
2216 2237
2217void 2238void
2218ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) 2239ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW
2219{ 2240{
2220 release_cb = release; 2241 release_cb = release;
2221 acquire_cb = acquire; 2242 acquire_cb = acquire;
2222} 2243}
2223#endif 2244#endif
2224 2245
2225/* initialise a loop structure, must be zero-initialised */ 2246/* initialise a loop structure, must be zero-initialised */
2226static void noinline ecb_cold 2247static void noinline ecb_cold
2227loop_init (EV_P_ unsigned int flags) 2248loop_init (EV_P_ unsigned int flags) EV_THROW
2228{ 2249{
2229 if (!backend) 2250 if (!backend)
2230 { 2251 {
2231 origflags = flags; 2252 origflags = flags;
2232 2253
2485} 2506}
2486 2507
2487#if EV_MULTIPLICITY 2508#if EV_MULTIPLICITY
2488 2509
2489struct ev_loop * ecb_cold 2510struct ev_loop * ecb_cold
2490ev_loop_new (unsigned int flags) 2511ev_loop_new (unsigned int flags) EV_THROW
2491{ 2512{
2492 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 2513 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
2493 2514
2494 memset (EV_A, 0, sizeof (struct ev_loop)); 2515 memset (EV_A, 0, sizeof (struct ev_loop));
2495 loop_init (EV_A_ flags); 2516 loop_init (EV_A_ flags);
2539} 2560}
2540#endif 2561#endif
2541 2562
2542#if EV_FEATURE_API 2563#if EV_FEATURE_API
2543void ecb_cold 2564void ecb_cold
2544ev_verify (EV_P) 2565ev_verify (EV_P) EV_THROW
2545{ 2566{
2546#if EV_VERIFY 2567#if EV_VERIFY
2547 int i; 2568 int i, j;
2548 WL w; 2569 WL w, w2;
2549 2570
2550 assert (activecnt >= -1); 2571 assert (activecnt >= -1);
2551 2572
2552 assert (fdchangemax >= fdchangecnt); 2573 assert (fdchangemax >= fdchangecnt);
2553 for (i = 0; i < fdchangecnt; ++i) 2574 for (i = 0; i < fdchangecnt; ++i)
2554 assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); 2575 assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0));
2555 2576
2556 assert (anfdmax >= 0); 2577 assert (anfdmax >= 0);
2557 for (i = 0; i < anfdmax; ++i) 2578 for (i = j = 0; i < anfdmax; ++i)
2558 for (w = anfds [i].head; w; w = w->next) 2579 for (w = w2 = anfds [i].head; w; w = w->next)
2559 { 2580 {
2560 verify_watcher (EV_A_ (W)w); 2581 verify_watcher (EV_A_ (W)w);
2582
2583 if (j++ & 1)
2584 {
2585 assert (("libev: io watcher list contains a loop", w != w2));
2586 w2 = w2->next;
2587 }
2588
2561 assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); 2589 assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1));
2562 assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); 2590 assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i));
2563 } 2591 }
2564 2592
2565 assert (timermax >= timercnt); 2593 assert (timermax >= timercnt);
2618#if EV_MULTIPLICITY 2646#if EV_MULTIPLICITY
2619struct ev_loop * ecb_cold 2647struct ev_loop * ecb_cold
2620#else 2648#else
2621int 2649int
2622#endif 2650#endif
2623ev_default_loop (unsigned int flags) 2651ev_default_loop (unsigned int flags) EV_THROW
2624{ 2652{
2625 if (!ev_default_loop_ptr) 2653 if (!ev_default_loop_ptr)
2626 { 2654 {
2627#if EV_MULTIPLICITY 2655#if EV_MULTIPLICITY
2628 EV_P = ev_default_loop_ptr = &default_loop_struct; 2656 EV_P = ev_default_loop_ptr = &default_loop_struct;
2647 2675
2648 return ev_default_loop_ptr; 2676 return ev_default_loop_ptr;
2649} 2677}
2650 2678
2651void 2679void
2652ev_loop_fork (EV_P) 2680ev_loop_fork (EV_P) EV_THROW
2653{ 2681{
2654 postfork = 1; /* must be in line with ev_default_fork */ 2682 postfork = 1; /* must be in line with ev_default_fork */
2655} 2683}
2656 2684
2657/*****************************************************************************/ 2685/*****************************************************************************/
2661{ 2689{
2662 EV_CB_INVOKE ((W)w, revents); 2690 EV_CB_INVOKE ((W)w, revents);
2663} 2691}
2664 2692
2665unsigned int 2693unsigned int
2666ev_pending_count (EV_P) 2694ev_pending_count (EV_P) EV_THROW
2667{ 2695{
2668 int pri; 2696 int pri;
2669 unsigned int count = 0; 2697 unsigned int count = 0;
2670 2698
2671 for (pri = NUMPRI; pri--; ) 2699 for (pri = NUMPRI; pri--; )
2675} 2703}
2676 2704
2677void noinline 2705void noinline
2678ev_invoke_pending (EV_P) 2706ev_invoke_pending (EV_P)
2679{ 2707{
2680 int pri; 2708 for (pendingpri = NUMPRI; pendingpri--; ) /* pendingpri is modified during the loop */
2681
2682 for (pri = NUMPRI; pri--; )
2683 while (pendingcnt [pri]) 2709 while (pendingcnt [pendingpri])
2684 { 2710 {
2685 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 2711 ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri];
2686 2712
2687 p->w->pending = 0; 2713 p->w->pending = 0;
2688 EV_CB_INVOKE (p->w, p->events); 2714 EV_CB_INVOKE (p->w, p->events);
2689 EV_FREQUENT_CHECK; 2715 EV_FREQUENT_CHECK;
2690 } 2716 }
3102 3128
3103 return activecnt; 3129 return activecnt;
3104} 3130}
3105 3131
3106void 3132void
3107ev_break (EV_P_ int how) 3133ev_break (EV_P_ int how) EV_THROW
3108{ 3134{
3109 loop_done = how; 3135 loop_done = how;
3110} 3136}
3111 3137
3112void 3138void
3113ev_ref (EV_P) 3139ev_ref (EV_P) EV_THROW
3114{ 3140{
3115 ++activecnt; 3141 ++activecnt;
3116} 3142}
3117 3143
3118void 3144void
3119ev_unref (EV_P) 3145ev_unref (EV_P) EV_THROW
3120{ 3146{
3121 --activecnt; 3147 --activecnt;
3122} 3148}
3123 3149
3124void 3150void
3125ev_now_update (EV_P) 3151ev_now_update (EV_P) EV_THROW
3126{ 3152{
3127 time_update (EV_A_ 1e100); 3153 time_update (EV_A_ 1e100);
3128} 3154}
3129 3155
3130void 3156void
3131ev_suspend (EV_P) 3157ev_suspend (EV_P) EV_THROW
3132{ 3158{
3133 ev_now_update (EV_A); 3159 ev_now_update (EV_A);
3134} 3160}
3135 3161
3136void 3162void
3137ev_resume (EV_P) 3163ev_resume (EV_P) EV_THROW
3138{ 3164{
3139 ev_tstamp mn_prev = mn_now; 3165 ev_tstamp mn_prev = mn_now;
3140 3166
3141 ev_now_update (EV_A); 3167 ev_now_update (EV_A);
3142 timers_reschedule (EV_A_ mn_now - mn_prev); 3168 timers_reschedule (EV_A_ mn_now - mn_prev);
3181 w->pending = 0; 3207 w->pending = 0;
3182 } 3208 }
3183} 3209}
3184 3210
3185int 3211int
3186ev_clear_pending (EV_P_ void *w) 3212ev_clear_pending (EV_P_ void *w) EV_THROW
3187{ 3213{
3188 W w_ = (W)w; 3214 W w_ = (W)w;
3189 int pending = w_->pending; 3215 int pending = w_->pending;
3190 3216
3191 if (expect_true (pending)) 3217 if (expect_true (pending))
3224} 3250}
3225 3251
3226/*****************************************************************************/ 3252/*****************************************************************************/
3227 3253
3228void noinline 3254void noinline
3229ev_io_start (EV_P_ ev_io *w) 3255ev_io_start (EV_P_ ev_io *w) EV_THROW
3230{ 3256{
3231 int fd = w->fd; 3257 int fd = w->fd;
3232 3258
3233 if (expect_false (ev_is_active (w))) 3259 if (expect_false (ev_is_active (w)))
3234 return; 3260 return;
3240 3266
3241 ev_start (EV_A_ (W)w, 1); 3267 ev_start (EV_A_ (W)w, 1);
3242 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); 3268 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero);
3243 wlist_add (&anfds[fd].head, (WL)w); 3269 wlist_add (&anfds[fd].head, (WL)w);
3244 3270
3271 /* common bug, apparently */
3272 assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w));
3273
3245 fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); 3274 fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY);
3246 w->events &= ~EV__IOFDSET; 3275 w->events &= ~EV__IOFDSET;
3247 3276
3248 EV_FREQUENT_CHECK; 3277 EV_FREQUENT_CHECK;
3249} 3278}
3250 3279
3251void noinline 3280void noinline
3252ev_io_stop (EV_P_ ev_io *w) 3281ev_io_stop (EV_P_ ev_io *w) EV_THROW
3253{ 3282{
3254 clear_pending (EV_A_ (W)w); 3283 clear_pending (EV_A_ (W)w);
3255 if (expect_false (!ev_is_active (w))) 3284 if (expect_false (!ev_is_active (w)))
3256 return; 3285 return;
3257 3286
3266 3295
3267 EV_FREQUENT_CHECK; 3296 EV_FREQUENT_CHECK;
3268} 3297}
3269 3298
3270void noinline 3299void noinline
3271ev_timer_start (EV_P_ ev_timer *w) 3300ev_timer_start (EV_P_ ev_timer *w) EV_THROW
3272{ 3301{
3273 if (expect_false (ev_is_active (w))) 3302 if (expect_false (ev_is_active (w)))
3274 return; 3303 return;
3275 3304
3276 ev_at (w) += mn_now; 3305 ev_at (w) += mn_now;
3290 3319
3291 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ 3320 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/
3292} 3321}
3293 3322
3294void noinline 3323void noinline
3295ev_timer_stop (EV_P_ ev_timer *w) 3324ev_timer_stop (EV_P_ ev_timer *w) EV_THROW
3296{ 3325{
3297 clear_pending (EV_A_ (W)w); 3326 clear_pending (EV_A_ (W)w);
3298 if (expect_false (!ev_is_active (w))) 3327 if (expect_false (!ev_is_active (w)))
3299 return; 3328 return;
3300 3329
3320 3349
3321 EV_FREQUENT_CHECK; 3350 EV_FREQUENT_CHECK;
3322} 3351}
3323 3352
3324void noinline 3353void noinline
3325ev_timer_again (EV_P_ ev_timer *w) 3354ev_timer_again (EV_P_ ev_timer *w) EV_THROW
3326{ 3355{
3327 EV_FREQUENT_CHECK; 3356 EV_FREQUENT_CHECK;
3328 3357
3329 clear_pending (EV_A_ (W)w); 3358 clear_pending (EV_A_ (W)w);
3330 3359
3347 3376
3348 EV_FREQUENT_CHECK; 3377 EV_FREQUENT_CHECK;
3349} 3378}
3350 3379
3351ev_tstamp 3380ev_tstamp
3352ev_timer_remaining (EV_P_ ev_timer *w) 3381ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW
3353{ 3382{
3354 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 3383 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
3355} 3384}
3356 3385
3357#if EV_PERIODIC_ENABLE 3386#if EV_PERIODIC_ENABLE
3358void noinline 3387void noinline
3359ev_periodic_start (EV_P_ ev_periodic *w) 3388ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW
3360{ 3389{
3361 if (expect_false (ev_is_active (w))) 3390 if (expect_false (ev_is_active (w)))
3362 return; 3391 return;
3363 3392
3364 if (w->reschedule_cb) 3393 if (w->reschedule_cb)
3384 3413
3385 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ 3414 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/
3386} 3415}
3387 3416
3388void noinline 3417void noinline
3389ev_periodic_stop (EV_P_ ev_periodic *w) 3418ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW
3390{ 3419{
3391 clear_pending (EV_A_ (W)w); 3420 clear_pending (EV_A_ (W)w);
3392 if (expect_false (!ev_is_active (w))) 3421 if (expect_false (!ev_is_active (w)))
3393 return; 3422 return;
3394 3423
3412 3441
3413 EV_FREQUENT_CHECK; 3442 EV_FREQUENT_CHECK;
3414} 3443}
3415 3444
3416void noinline 3445void noinline
3417ev_periodic_again (EV_P_ ev_periodic *w) 3446ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW
3418{ 3447{
3419 /* TODO: use adjustheap and recalculation */ 3448 /* TODO: use adjustheap and recalculation */
3420 ev_periodic_stop (EV_A_ w); 3449 ev_periodic_stop (EV_A_ w);
3421 ev_periodic_start (EV_A_ w); 3450 ev_periodic_start (EV_A_ w);
3422} 3451}
3427#endif 3456#endif
3428 3457
3429#if EV_SIGNAL_ENABLE 3458#if EV_SIGNAL_ENABLE
3430 3459
3431void noinline 3460void noinline
3432ev_signal_start (EV_P_ ev_signal *w) 3461ev_signal_start (EV_P_ ev_signal *w) EV_THROW
3433{ 3462{
3434 if (expect_false (ev_is_active (w))) 3463 if (expect_false (ev_is_active (w)))
3435 return; 3464 return;
3436 3465
3437 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); 3466 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG));
3508 3537
3509 EV_FREQUENT_CHECK; 3538 EV_FREQUENT_CHECK;
3510} 3539}
3511 3540
3512void noinline 3541void noinline
3513ev_signal_stop (EV_P_ ev_signal *w) 3542ev_signal_stop (EV_P_ ev_signal *w) EV_THROW
3514{ 3543{
3515 clear_pending (EV_A_ (W)w); 3544 clear_pending (EV_A_ (W)w);
3516 if (expect_false (!ev_is_active (w))) 3545 if (expect_false (!ev_is_active (w)))
3517 return; 3546 return;
3518 3547
3549#endif 3578#endif
3550 3579
3551#if EV_CHILD_ENABLE 3580#if EV_CHILD_ENABLE
3552 3581
3553void 3582void
3554ev_child_start (EV_P_ ev_child *w) 3583ev_child_start (EV_P_ ev_child *w) EV_THROW
3555{ 3584{
3556#if EV_MULTIPLICITY 3585#if EV_MULTIPLICITY
3557 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 3586 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
3558#endif 3587#endif
3559 if (expect_false (ev_is_active (w))) 3588 if (expect_false (ev_is_active (w)))
3566 3595
3567 EV_FREQUENT_CHECK; 3596 EV_FREQUENT_CHECK;
3568} 3597}
3569 3598
3570void 3599void
3571ev_child_stop (EV_P_ ev_child *w) 3600ev_child_stop (EV_P_ ev_child *w) EV_THROW
3572{ 3601{
3573 clear_pending (EV_A_ (W)w); 3602 clear_pending (EV_A_ (W)w);
3574 if (expect_false (!ev_is_active (w))) 3603 if (expect_false (!ev_is_active (w)))
3575 return; 3604 return;
3576 3605
3828#else 3857#else
3829# define EV_LSTAT(p,b) lstat (p, b) 3858# define EV_LSTAT(p,b) lstat (p, b)
3830#endif 3859#endif
3831 3860
3832void 3861void
3833ev_stat_stat (EV_P_ ev_stat *w) 3862ev_stat_stat (EV_P_ ev_stat *w) EV_THROW
3834{ 3863{
3835 if (lstat (w->path, &w->attr) < 0) 3864 if (lstat (w->path, &w->attr) < 0)
3836 w->attr.st_nlink = 0; 3865 w->attr.st_nlink = 0;
3837 else if (!w->attr.st_nlink) 3866 else if (!w->attr.st_nlink)
3838 w->attr.st_nlink = 1; 3867 w->attr.st_nlink = 1;
3877 ev_feed_event (EV_A_ w, EV_STAT); 3906 ev_feed_event (EV_A_ w, EV_STAT);
3878 } 3907 }
3879} 3908}
3880 3909
3881void 3910void
3882ev_stat_start (EV_P_ ev_stat *w) 3911ev_stat_start (EV_P_ ev_stat *w) EV_THROW
3883{ 3912{
3884 if (expect_false (ev_is_active (w))) 3913 if (expect_false (ev_is_active (w)))
3885 return; 3914 return;
3886 3915
3887 ev_stat_stat (EV_A_ w); 3916 ev_stat_stat (EV_A_ w);
3908 3937
3909 EV_FREQUENT_CHECK; 3938 EV_FREQUENT_CHECK;
3910} 3939}
3911 3940
3912void 3941void
3913ev_stat_stop (EV_P_ ev_stat *w) 3942ev_stat_stop (EV_P_ ev_stat *w) EV_THROW
3914{ 3943{
3915 clear_pending (EV_A_ (W)w); 3944 clear_pending (EV_A_ (W)w);
3916 if (expect_false (!ev_is_active (w))) 3945 if (expect_false (!ev_is_active (w)))
3917 return; 3946 return;
3918 3947
3934} 3963}
3935#endif 3964#endif
3936 3965
3937#if EV_IDLE_ENABLE 3966#if EV_IDLE_ENABLE
3938void 3967void
3939ev_idle_start (EV_P_ ev_idle *w) 3968ev_idle_start (EV_P_ ev_idle *w) EV_THROW
3940{ 3969{
3941 if (expect_false (ev_is_active (w))) 3970 if (expect_false (ev_is_active (w)))
3942 return; 3971 return;
3943 3972
3944 pri_adjust (EV_A_ (W)w); 3973 pri_adjust (EV_A_ (W)w);
3957 3986
3958 EV_FREQUENT_CHECK; 3987 EV_FREQUENT_CHECK;
3959} 3988}
3960 3989
3961void 3990void
3962ev_idle_stop (EV_P_ ev_idle *w) 3991ev_idle_stop (EV_P_ ev_idle *w) EV_THROW
3963{ 3992{
3964 clear_pending (EV_A_ (W)w); 3993 clear_pending (EV_A_ (W)w);
3965 if (expect_false (!ev_is_active (w))) 3994 if (expect_false (!ev_is_active (w)))
3966 return; 3995 return;
3967 3996
3981} 4010}
3982#endif 4011#endif
3983 4012
3984#if EV_PREPARE_ENABLE 4013#if EV_PREPARE_ENABLE
3985void 4014void
3986ev_prepare_start (EV_P_ ev_prepare *w) 4015ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW
3987{ 4016{
3988 if (expect_false (ev_is_active (w))) 4017 if (expect_false (ev_is_active (w)))
3989 return; 4018 return;
3990 4019
3991 EV_FREQUENT_CHECK; 4020 EV_FREQUENT_CHECK;
3996 4025
3997 EV_FREQUENT_CHECK; 4026 EV_FREQUENT_CHECK;
3998} 4027}
3999 4028
4000void 4029void
4001ev_prepare_stop (EV_P_ ev_prepare *w) 4030ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW
4002{ 4031{
4003 clear_pending (EV_A_ (W)w); 4032 clear_pending (EV_A_ (W)w);
4004 if (expect_false (!ev_is_active (w))) 4033 if (expect_false (!ev_is_active (w)))
4005 return; 4034 return;
4006 4035
4019} 4048}
4020#endif 4049#endif
4021 4050
4022#if EV_CHECK_ENABLE 4051#if EV_CHECK_ENABLE
4023void 4052void
4024ev_check_start (EV_P_ ev_check *w) 4053ev_check_start (EV_P_ ev_check *w) EV_THROW
4025{ 4054{
4026 if (expect_false (ev_is_active (w))) 4055 if (expect_false (ev_is_active (w)))
4027 return; 4056 return;
4028 4057
4029 EV_FREQUENT_CHECK; 4058 EV_FREQUENT_CHECK;
4034 4063
4035 EV_FREQUENT_CHECK; 4064 EV_FREQUENT_CHECK;
4036} 4065}
4037 4066
4038void 4067void
4039ev_check_stop (EV_P_ ev_check *w) 4068ev_check_stop (EV_P_ ev_check *w) EV_THROW
4040{ 4069{
4041 clear_pending (EV_A_ (W)w); 4070 clear_pending (EV_A_ (W)w);
4042 if (expect_false (!ev_is_active (w))) 4071 if (expect_false (!ev_is_active (w)))
4043 return; 4072 return;
4044 4073
4057} 4086}
4058#endif 4087#endif
4059 4088
4060#if EV_EMBED_ENABLE 4089#if EV_EMBED_ENABLE
4061void noinline 4090void noinline
4062ev_embed_sweep (EV_P_ ev_embed *w) 4091ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW
4063{ 4092{
4064 ev_run (w->other, EVRUN_NOWAIT); 4093 ev_run (w->other, EVRUN_NOWAIT);
4065} 4094}
4066 4095
4067static void 4096static void
4115 ev_idle_stop (EV_A_ idle); 4144 ev_idle_stop (EV_A_ idle);
4116} 4145}
4117#endif 4146#endif
4118 4147
4119void 4148void
4120ev_embed_start (EV_P_ ev_embed *w) 4149ev_embed_start (EV_P_ ev_embed *w) EV_THROW
4121{ 4150{
4122 if (expect_false (ev_is_active (w))) 4151 if (expect_false (ev_is_active (w)))
4123 return; 4152 return;
4124 4153
4125 { 4154 {
4146 4175
4147 EV_FREQUENT_CHECK; 4176 EV_FREQUENT_CHECK;
4148} 4177}
4149 4178
4150void 4179void
4151ev_embed_stop (EV_P_ ev_embed *w) 4180ev_embed_stop (EV_P_ ev_embed *w) EV_THROW
4152{ 4181{
4153 clear_pending (EV_A_ (W)w); 4182 clear_pending (EV_A_ (W)w);
4154 if (expect_false (!ev_is_active (w))) 4183 if (expect_false (!ev_is_active (w)))
4155 return; 4184 return;
4156 4185
4166} 4195}
4167#endif 4196#endif
4168 4197
4169#if EV_FORK_ENABLE 4198#if EV_FORK_ENABLE
4170void 4199void
4171ev_fork_start (EV_P_ ev_fork *w) 4200ev_fork_start (EV_P_ ev_fork *w) EV_THROW
4172{ 4201{
4173 if (expect_false (ev_is_active (w))) 4202 if (expect_false (ev_is_active (w)))
4174 return; 4203 return;
4175 4204
4176 EV_FREQUENT_CHECK; 4205 EV_FREQUENT_CHECK;
4181 4210
4182 EV_FREQUENT_CHECK; 4211 EV_FREQUENT_CHECK;
4183} 4212}
4184 4213
4185void 4214void
4186ev_fork_stop (EV_P_ ev_fork *w) 4215ev_fork_stop (EV_P_ ev_fork *w) EV_THROW
4187{ 4216{
4188 clear_pending (EV_A_ (W)w); 4217 clear_pending (EV_A_ (W)w);
4189 if (expect_false (!ev_is_active (w))) 4218 if (expect_false (!ev_is_active (w)))
4190 return; 4219 return;
4191 4220
4204} 4233}
4205#endif 4234#endif
4206 4235
4207#if EV_CLEANUP_ENABLE 4236#if EV_CLEANUP_ENABLE
4208void 4237void
4209ev_cleanup_start (EV_P_ ev_cleanup *w) 4238ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW
4210{ 4239{
4211 if (expect_false (ev_is_active (w))) 4240 if (expect_false (ev_is_active (w)))
4212 return; 4241 return;
4213 4242
4214 EV_FREQUENT_CHECK; 4243 EV_FREQUENT_CHECK;
4221 ev_unref (EV_A); 4250 ev_unref (EV_A);
4222 EV_FREQUENT_CHECK; 4251 EV_FREQUENT_CHECK;
4223} 4252}
4224 4253
4225void 4254void
4226ev_cleanup_stop (EV_P_ ev_cleanup *w) 4255ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW
4227{ 4256{
4228 clear_pending (EV_A_ (W)w); 4257 clear_pending (EV_A_ (W)w);
4229 if (expect_false (!ev_is_active (w))) 4258 if (expect_false (!ev_is_active (w)))
4230 return; 4259 return;
4231 4260
4245} 4274}
4246#endif 4275#endif
4247 4276
4248#if EV_ASYNC_ENABLE 4277#if EV_ASYNC_ENABLE
4249void 4278void
4250ev_async_start (EV_P_ ev_async *w) 4279ev_async_start (EV_P_ ev_async *w) EV_THROW
4251{ 4280{
4252 if (expect_false (ev_is_active (w))) 4281 if (expect_false (ev_is_active (w)))
4253 return; 4282 return;
4254 4283
4255 w->sent = 0; 4284 w->sent = 0;
4264 4293
4265 EV_FREQUENT_CHECK; 4294 EV_FREQUENT_CHECK;
4266} 4295}
4267 4296
4268void 4297void
4269ev_async_stop (EV_P_ ev_async *w) 4298ev_async_stop (EV_P_ ev_async *w) EV_THROW
4270{ 4299{
4271 clear_pending (EV_A_ (W)w); 4300 clear_pending (EV_A_ (W)w);
4272 if (expect_false (!ev_is_active (w))) 4301 if (expect_false (!ev_is_active (w)))
4273 return; 4302 return;
4274 4303
4285 4314
4286 EV_FREQUENT_CHECK; 4315 EV_FREQUENT_CHECK;
4287} 4316}
4288 4317
4289void 4318void
4290ev_async_send (EV_P_ ev_async *w) 4319ev_async_send (EV_P_ ev_async *w) EV_THROW
4291{ 4320{
4292 w->sent = 1; 4321 w->sent = 1;
4293 evpipe_write (EV_A_ &async_pending); 4322 evpipe_write (EV_A_ &async_pending);
4294} 4323}
4295#endif 4324#endif
4332 4361
4333 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); 4362 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io));
4334} 4363}
4335 4364
4336void 4365void
4337ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 4366ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW
4338{ 4367{
4339 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 4368 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
4340 4369
4341 if (expect_false (!once)) 4370 if (expect_false (!once))
4342 { 4371 {
4364 4393
4365/*****************************************************************************/ 4394/*****************************************************************************/
4366 4395
4367#if EV_WALK_ENABLE 4396#if EV_WALK_ENABLE
4368void ecb_cold 4397void ecb_cold
4369ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) 4398ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW
4370{ 4399{
4371 int i, j; 4400 int i, j;
4372 ev_watcher_list *wl, *wn; 4401 ev_watcher_list *wl, *wn;
4373 4402
4374 if (types & (EV_IO | EV_EMBED)) 4403 if (types & (EV_IO | EV_EMBED))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines