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