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

Comparing libev/ev.c (file contents):
Revision 1.427 by root, Sun May 6 19:29:59 2012 UTC vs.
Revision 1.436 by root, Tue May 29 20:44:39 2012 UTC

201# include <sys/wait.h> 201# include <sys/wait.h>
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 <winsock2.h>
206# include <windows.h> 207# include <windows.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
408/* some very old inotify.h headers don't have IN_DONT_FOLLOW */ 409/* some very old inotify.h headers don't have IN_DONT_FOLLOW */
409# ifndef IN_DONT_FOLLOW 410# ifndef IN_DONT_FOLLOW
410# undef EV_USE_INOTIFY 411# undef EV_USE_INOTIFY
411# define EV_USE_INOTIFY 0 412# define EV_USE_INOTIFY 0
412# endif 413# endif
413#endif
414
415#if EV_SELECT_IS_WINSOCKET
416# include <winsock.h>
417#endif 414#endif
418 415
419#if EV_USE_EVENTFD 416#if EV_USE_EVENTFD
420/* 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 */
421# include <stdint.h> 418# include <stdint.h>
1108#endif 1105#endif
1109 1106
1110static void (*syserr_cb)(const char *msg) EV_THROW; 1107static void (*syserr_cb)(const char *msg) EV_THROW;
1111 1108
1112void ecb_cold 1109void ecb_cold
1113ev_set_syserr_cb (void (*cb)(const char *msg)) EV_THROW 1110ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW
1114{ 1111{
1115 syserr_cb = cb; 1112 syserr_cb = cb;
1116} 1113}
1117 1114
1118static void noinline ecb_cold 1115static void noinline ecb_cold
1136 abort (); 1133 abort ();
1137 } 1134 }
1138} 1135}
1139 1136
1140static void * 1137static void *
1141ev_realloc_emul (void *ptr, long size) 1138ev_realloc_emul (void *ptr, long size) EV_THROW
1142{ 1139{
1143#if __GLIBC__ 1140#if __GLIBC__
1144 return realloc (ptr, size); 1141 return realloc (ptr, size);
1145#else 1142#else
1146 /* some systems, notably openbsd and darwin, fail to properly 1143 /* some systems, notably openbsd and darwin, fail to properly
1157} 1154}
1158 1155
1159static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; 1156static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul;
1160 1157
1161void ecb_cold 1158void ecb_cold
1162ev_set_allocator (void *(*cb)(void *ptr, long size)) EV_THROW 1159ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW
1163{ 1160{
1164 alloc = cb; 1161 alloc = cb;
1165} 1162}
1166 1163
1167inline_speed void * 1164inline_speed void *
1852 1849
1853 if (expect_true (*flag)) 1850 if (expect_true (*flag))
1854 return; 1851 return;
1855 1852
1856 *flag = 1; 1853 *flag = 1;
1857
1858 ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ 1854 ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */
1859 1855
1860 pipe_write_skipped = 1; 1856 pipe_write_skipped = 1;
1861 1857
1862 ECB_MEMORY_FENCE; /* make sure pipe_write_skipped is visible before we check pipe_write_wanted */ 1858 ECB_MEMORY_FENCE; /* make sure pipe_write_skipped is visible before we check pipe_write_wanted */
1863 1859
1864 if (pipe_write_wanted) 1860 if (pipe_write_wanted)
1865 { 1861 {
1866 int old_errno; 1862 int old_errno;
1867 1863
1868 pipe_write_skipped = 0; /* just an optimisation, no fence needed */ 1864 pipe_write_skipped = 0;
1865 ECB_MEMORY_FENCE_RELEASE;
1869 1866
1870 old_errno = errno; /* save errno because write will clobber it */ 1867 old_errno = errno; /* save errno because write will clobber it */
1871 1868
1872#if EV_USE_EVENTFD 1869#if EV_USE_EVENTFD
1873 if (evfd >= 0) 1870 if (evfd >= 0)
1913 { 1910 {
1914 char dummy[4]; 1911 char dummy[4];
1915#ifdef _WIN32 1912#ifdef _WIN32
1916 WSABUF buf; 1913 WSABUF buf;
1917 DWORD recvd; 1914 DWORD recvd;
1915 DWORD flags = 0;
1918 buf.buf = dummy; 1916 buf.buf = dummy;
1919 buf.len = sizeof (dummy); 1917 buf.len = sizeof (dummy);
1920 WSARecv (EV_FD_TO_WIN32_HANDLE (evpipe [0]), &buf, 1, &recvd, 0, 0, 0); 1918 WSARecv (EV_FD_TO_WIN32_HANDLE (evpipe [0]), &buf, 1, &recvd, &flags, 0, 0);
1921#else 1919#else
1922 read (evpipe [0], &dummy, sizeof (dummy)); 1920 read (evpipe [0], &dummy, sizeof (dummy));
1923#endif 1921#endif
1924 } 1922 }
1925 } 1923 }
1931#if EV_SIGNAL_ENABLE 1929#if EV_SIGNAL_ENABLE
1932 if (sig_pending) 1930 if (sig_pending)
1933 { 1931 {
1934 sig_pending = 0; 1932 sig_pending = 0;
1935 1933
1936 ECB_MEMORY_FENCE_RELEASE; 1934 ECB_MEMORY_FENCE;
1937 1935
1938 for (i = EV_NSIG - 1; i--; ) 1936 for (i = EV_NSIG - 1; i--; )
1939 if (expect_false (signals [i].pending)) 1937 if (expect_false (signals [i].pending))
1940 ev_feed_signal_event (EV_A_ i + 1); 1938 ev_feed_signal_event (EV_A_ i + 1);
1941 } 1939 }
1944#if EV_ASYNC_ENABLE 1942#if EV_ASYNC_ENABLE
1945 if (async_pending) 1943 if (async_pending)
1946 { 1944 {
1947 async_pending = 0; 1945 async_pending = 0;
1948 1946
1949 ECB_MEMORY_FENCE_RELEASE; 1947 ECB_MEMORY_FENCE;
1950 1948
1951 for (i = asynccnt; i--; ) 1949 for (i = asynccnt; i--; )
1952 if (asyncs [i]->sent) 1950 if (asyncs [i]->sent)
1953 { 1951 {
1954 asyncs [i]->sent = 0; 1952 asyncs [i]->sent = 0;
1953 ECB_MEMORY_FENCE_RELEASE;
1955 ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); 1954 ev_feed_event (EV_A_ asyncs [i], EV_ASYNC);
1956 } 1955 }
1957 } 1956 }
1958#endif 1957#endif
1959} 1958}
2004 if (expect_false (signals [signum].loop != EV_A)) 2003 if (expect_false (signals [signum].loop != EV_A))
2005 return; 2004 return;
2006#endif 2005#endif
2007 2006
2008 signals [signum].pending = 0; 2007 signals [signum].pending = 0;
2008 MEMORY_FENCE_RELEASE;
2009 2009
2010 for (w = signals [signum].head; w; w = w->next) 2010 for (w = signals [signum].head; w; w = w->next)
2011 ev_feed_event (EV_A_ (W)w, EV_SIGNAL); 2011 ev_feed_event (EV_A_ (W)w, EV_SIGNAL);
2012} 2012}
2013 2013
2357 EV_INVOKE_PENDING; 2357 EV_INVOKE_PENDING;
2358 } 2358 }
2359#endif 2359#endif
2360 2360
2361#if EV_CHILD_ENABLE 2361#if EV_CHILD_ENABLE
2362 if (ev_is_active (&childev)) 2362 if (ev_is_default_loop (EV_A) && ev_is_active (&childev))
2363 { 2363 {
2364 ev_ref (EV_A); /* child watcher */ 2364 ev_ref (EV_A); /* child watcher */
2365 ev_signal_stop (EV_A_ &childev); 2365 ev_signal_stop (EV_A_ &childev);
2366 } 2366 }
2367#endif 2367#endif
2562#if EV_FEATURE_API 2562#if EV_FEATURE_API
2563void ecb_cold 2563void ecb_cold
2564ev_verify (EV_P) EV_THROW 2564ev_verify (EV_P) EV_THROW
2565{ 2565{
2566#if EV_VERIFY 2566#if EV_VERIFY
2567 int i, j; 2567 int i;
2568 WL w, w2; 2568 WL w, w2;
2569 2569
2570 assert (activecnt >= -1); 2570 assert (activecnt >= -1);
2571 2571
2572 assert (fdchangemax >= fdchangecnt); 2572 assert (fdchangemax >= fdchangecnt);
2573 for (i = 0; i < fdchangecnt; ++i) 2573 for (i = 0; i < fdchangecnt; ++i)
2574 assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); 2574 assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0));
2575 2575
2576 assert (anfdmax >= 0); 2576 assert (anfdmax >= 0);
2577 for (i = j = 0; i < anfdmax; ++i) 2577 for (i = 0; i < anfdmax; ++i)
2578 {
2579 int j = 0;
2580
2578 for (w = w2 = anfds [i].head; w; w = w->next) 2581 for (w = w2 = anfds [i].head; w; w = w->next)
2579 { 2582 {
2580 verify_watcher (EV_A_ (W)w); 2583 verify_watcher (EV_A_ (W)w);
2581 2584
2582 if (++j & 1) 2585 if (j++ & 1)
2583 w2 = w2->next; 2586 {
2584
2585 assert (("libev: io watcher list contains a loop", w != w2)); 2587 assert (("libev: io watcher list contains a loop", w != w2));
2588 w2 = w2->next;
2589 }
2590
2586 assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); 2591 assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1));
2587 assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); 2592 assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i));
2588 } 2593 }
2594 }
2589 2595
2590 assert (timermax >= timercnt); 2596 assert (timermax >= timercnt);
2591 verify_heap (EV_A_ timers, timercnt); 2597 verify_heap (EV_A_ timers, timercnt);
2592 2598
2593#if EV_PERIODIC_ENABLE 2599#if EV_PERIODIC_ENABLE
2808{ 2814{
2809 EV_FREQUENT_CHECK; 2815 EV_FREQUENT_CHECK;
2810 2816
2811 while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) 2817 while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now)
2812 { 2818 {
2813 int feed_count = 0;
2814
2815 do 2819 do
2816 { 2820 {
2817 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); 2821 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]);
2818 2822
2819 /*assert (("libev: inactive timer on periodic heap detected", ev_is_active (w)));*/ 2823 /*assert (("libev: inactive timer on periodic heap detected", ev_is_active (w)));*/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines