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

Comparing libev/ev.c (file contents):
Revision 1.430 by root, Wed May 9 16:50:23 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# include <winsock2.h>
208# ifndef EV_SELECT_IS_WINSOCKET 208# ifndef EV_SELECT_IS_WINSOCKET
209# define EV_SELECT_IS_WINSOCKET 1 209# define EV_SELECT_IS_WINSOCKET 1
210# endif 210# endif
211# undef EV_AVOID_STDIO 211# undef EV_AVOID_STDIO
212#endif 212#endif
1105#endif 1105#endif
1106 1106
1107static void (*syserr_cb)(const char *msg) EV_THROW; 1107static void (*syserr_cb)(const char *msg) EV_THROW;
1108 1108
1109void ecb_cold 1109void ecb_cold
1110ev_set_syserr_cb (void (*cb)(const char *msg)) EV_THROW 1110ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW
1111{ 1111{
1112 syserr_cb = cb; 1112 syserr_cb = cb;
1113} 1113}
1114 1114
1115static void noinline ecb_cold 1115static void noinline ecb_cold
1133 abort (); 1133 abort ();
1134 } 1134 }
1135} 1135}
1136 1136
1137static void * 1137static void *
1138ev_realloc_emul (void *ptr, long size) 1138ev_realloc_emul (void *ptr, long size) EV_THROW
1139{ 1139{
1140#if __GLIBC__ 1140#if __GLIBC__
1141 return realloc (ptr, size); 1141 return realloc (ptr, size);
1142#else 1142#else
1143 /* some systems, notably openbsd and darwin, fail to properly 1143 /* some systems, notably openbsd and darwin, fail to properly
1154} 1154}
1155 1155
1156static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; 1156static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul;
1157 1157
1158void ecb_cold 1158void ecb_cold
1159ev_set_allocator (void *(*cb)(void *ptr, long size)) EV_THROW 1159ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW
1160{ 1160{
1161 alloc = cb; 1161 alloc = cb;
1162} 1162}
1163 1163
1164inline_speed void * 1164inline_speed void *
1849 1849
1850 if (expect_true (*flag)) 1850 if (expect_true (*flag))
1851 return; 1851 return;
1852 1852
1853 *flag = 1; 1853 *flag = 1;
1854
1855 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 */
1856 1855
1857 pipe_write_skipped = 1; 1856 pipe_write_skipped = 1;
1858 1857
1859 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 */
1860 1859
1861 if (pipe_write_wanted) 1860 if (pipe_write_wanted)
1862 { 1861 {
1863 int old_errno; 1862 int old_errno;
1864 1863
1865 pipe_write_skipped = 0; /* just an optimisation, no fence needed */ 1864 pipe_write_skipped = 0;
1865 ECB_MEMORY_FENCE_RELEASE;
1866 1866
1867 old_errno = errno; /* save errno because write will clobber it */ 1867 old_errno = errno; /* save errno because write will clobber it */
1868 1868
1869#if EV_USE_EVENTFD 1869#if EV_USE_EVENTFD
1870 if (evfd >= 0) 1870 if (evfd >= 0)
1910 { 1910 {
1911 char dummy[4]; 1911 char dummy[4];
1912#ifdef _WIN32 1912#ifdef _WIN32
1913 WSABUF buf; 1913 WSABUF buf;
1914 DWORD recvd; 1914 DWORD recvd;
1915 DWORD flags = 0;
1915 buf.buf = dummy; 1916 buf.buf = dummy;
1916 buf.len = sizeof (dummy); 1917 buf.len = sizeof (dummy);
1917 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);
1918#else 1919#else
1919 read (evpipe [0], &dummy, sizeof (dummy)); 1920 read (evpipe [0], &dummy, sizeof (dummy));
1920#endif 1921#endif
1921 } 1922 }
1922 } 1923 }
1928#if EV_SIGNAL_ENABLE 1929#if EV_SIGNAL_ENABLE
1929 if (sig_pending) 1930 if (sig_pending)
1930 { 1931 {
1931 sig_pending = 0; 1932 sig_pending = 0;
1932 1933
1933 ECB_MEMORY_FENCE_RELEASE; 1934 ECB_MEMORY_FENCE;
1934 1935
1935 for (i = EV_NSIG - 1; i--; ) 1936 for (i = EV_NSIG - 1; i--; )
1936 if (expect_false (signals [i].pending)) 1937 if (expect_false (signals [i].pending))
1937 ev_feed_signal_event (EV_A_ i + 1); 1938 ev_feed_signal_event (EV_A_ i + 1);
1938 } 1939 }
1941#if EV_ASYNC_ENABLE 1942#if EV_ASYNC_ENABLE
1942 if (async_pending) 1943 if (async_pending)
1943 { 1944 {
1944 async_pending = 0; 1945 async_pending = 0;
1945 1946
1946 ECB_MEMORY_FENCE_RELEASE; 1947 ECB_MEMORY_FENCE;
1947 1948
1948 for (i = asynccnt; i--; ) 1949 for (i = asynccnt; i--; )
1949 if (asyncs [i]->sent) 1950 if (asyncs [i]->sent)
1950 { 1951 {
1951 asyncs [i]->sent = 0; 1952 asyncs [i]->sent = 0;
1953 ECB_MEMORY_FENCE_RELEASE;
1952 ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); 1954 ev_feed_event (EV_A_ asyncs [i], EV_ASYNC);
1953 } 1955 }
1954 } 1956 }
1955#endif 1957#endif
1956} 1958}
2001 if (expect_false (signals [signum].loop != EV_A)) 2003 if (expect_false (signals [signum].loop != EV_A))
2002 return; 2004 return;
2003#endif 2005#endif
2004 2006
2005 signals [signum].pending = 0; 2007 signals [signum].pending = 0;
2008 MEMORY_FENCE_RELEASE;
2006 2009
2007 for (w = signals [signum].head; w; w = w->next) 2010 for (w = signals [signum].head; w; w = w->next)
2008 ev_feed_event (EV_A_ (W)w, EV_SIGNAL); 2011 ev_feed_event (EV_A_ (W)w, EV_SIGNAL);
2009} 2012}
2010 2013
2354 EV_INVOKE_PENDING; 2357 EV_INVOKE_PENDING;
2355 } 2358 }
2356#endif 2359#endif
2357 2360
2358#if EV_CHILD_ENABLE 2361#if EV_CHILD_ENABLE
2359 if (ev_is_active (&childev)) 2362 if (ev_is_default_loop (EV_A) && ev_is_active (&childev))
2360 { 2363 {
2361 ev_ref (EV_A); /* child watcher */ 2364 ev_ref (EV_A); /* child watcher */
2362 ev_signal_stop (EV_A_ &childev); 2365 ev_signal_stop (EV_A_ &childev);
2363 } 2366 }
2364#endif 2367#endif
2811{ 2814{
2812 EV_FREQUENT_CHECK; 2815 EV_FREQUENT_CHECK;
2813 2816
2814 while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) 2817 while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now)
2815 { 2818 {
2816 int feed_count = 0;
2817
2818 do 2819 do
2819 { 2820 {
2820 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); 2821 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]);
2821 2822
2822 /*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