… | |
… | |
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 |
… | |
… | |
1430 | w_->pending = ++pendingcnt [pri]; |
1431 | w_->pending = ++pendingcnt [pri]; |
1431 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1432 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1432 | pendings [pri][w_->pending - 1].w = w_; |
1433 | pendings [pri][w_->pending - 1].w = w_; |
1433 | pendings [pri][w_->pending - 1].events = revents; |
1434 | pendings [pri][w_->pending - 1].events = revents; |
1434 | } |
1435 | } |
|
|
1436 | |
|
|
1437 | pendingpri = NUMPRI - 1; |
1435 | } |
1438 | } |
1436 | |
1439 | |
1437 | inline_speed void |
1440 | inline_speed void |
1438 | feed_reverse (EV_P_ W w) |
1441 | feed_reverse (EV_P_ W w) |
1439 | { |
1442 | { |
… | |
… | |
1844 | } |
1847 | } |
1845 | |
1848 | |
1846 | inline_speed void |
1849 | inline_speed void |
1847 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1850 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1848 | { |
1851 | { |
|
|
1852 | ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ |
|
|
1853 | |
1849 | if (expect_true (*flag)) |
1854 | if (expect_true (*flag)) |
1850 | return; |
1855 | return; |
1851 | |
1856 | |
1852 | *flag = 1; |
1857 | *flag = 1; |
1853 | |
1858 | |
… | |
… | |
1872 | write (evfd, &counter, sizeof (uint64_t)); |
1877 | write (evfd, &counter, sizeof (uint64_t)); |
1873 | } |
1878 | } |
1874 | else |
1879 | else |
1875 | #endif |
1880 | #endif |
1876 | { |
1881 | { |
1877 | /* win32 people keep sending patches that change this write() to send() */ |
1882 | #ifdef _WIN32 |
1878 | /* and then run away. but send() is wrong, it wants a socket handle on win32 */ |
1883 | WSABUF buf; |
1879 | /* so when you think this write should be a send instead, please find out */ |
1884 | DWORD sent; |
1880 | /* where your send() is from - it's definitely not the microsoft send, and */ |
1885 | buf.buf = &buf; |
1881 | /* tell me. thank you. */ |
1886 | buf.len = 1; |
1882 | /* 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); |
1883 | /* check the ev documentation on how to use this flag */ |
1888 | #else |
1884 | write (evpipe [1], &(evpipe [1]), 1); |
1889 | write (evpipe [1], &(evpipe [1]), 1); |
|
|
1890 | #endif |
1885 | } |
1891 | } |
1886 | |
1892 | |
1887 | errno = old_errno; |
1893 | errno = old_errno; |
1888 | } |
1894 | } |
1889 | } |
1895 | } |
… | |
… | |
1904 | read (evfd, &counter, sizeof (uint64_t)); |
1910 | read (evfd, &counter, sizeof (uint64_t)); |
1905 | } |
1911 | } |
1906 | else |
1912 | else |
1907 | #endif |
1913 | #endif |
1908 | { |
1914 | { |
1909 | char dummy; |
1915 | char dummy[4]; |
1910 | /* 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 |
1911 | read (evpipe [0], &dummy, 1); |
1923 | read (evpipe [0], &dummy, sizeof (dummy)); |
|
|
1924 | #endif |
1912 | } |
1925 | } |
1913 | } |
1926 | } |
1914 | |
1927 | |
1915 | pipe_write_skipped = 0; |
1928 | pipe_write_skipped = 0; |
|
|
1929 | |
|
|
1930 | ECB_MEMORY_FENCE; /* push out skipped, acquire flags */ |
1916 | |
1931 | |
1917 | #if EV_SIGNAL_ENABLE |
1932 | #if EV_SIGNAL_ENABLE |
1918 | if (sig_pending) |
1933 | if (sig_pending) |
1919 | { |
1934 | { |
1920 | sig_pending = 0; |
1935 | sig_pending = 0; |
|
|
1936 | |
|
|
1937 | ECB_MEMORY_FENCE_RELEASE; |
1921 | |
1938 | |
1922 | for (i = EV_NSIG - 1; i--; ) |
1939 | for (i = EV_NSIG - 1; i--; ) |
1923 | if (expect_false (signals [i].pending)) |
1940 | if (expect_false (signals [i].pending)) |
1924 | ev_feed_signal_event (EV_A_ i + 1); |
1941 | ev_feed_signal_event (EV_A_ i + 1); |
1925 | } |
1942 | } |
… | |
… | |
1927 | |
1944 | |
1928 | #if EV_ASYNC_ENABLE |
1945 | #if EV_ASYNC_ENABLE |
1929 | if (async_pending) |
1946 | if (async_pending) |
1930 | { |
1947 | { |
1931 | async_pending = 0; |
1948 | async_pending = 0; |
|
|
1949 | |
|
|
1950 | ECB_MEMORY_FENCE_RELEASE; |
1932 | |
1951 | |
1933 | for (i = asynccnt; i--; ) |
1952 | for (i = asynccnt; i--; ) |
1934 | if (asyncs [i]->sent) |
1953 | if (asyncs [i]->sent) |
1935 | { |
1954 | { |
1936 | asyncs [i]->sent = 0; |
1955 | asyncs [i]->sent = 0; |
… | |
… | |
2215 | { |
2234 | { |
2216 | invoke_cb = invoke_pending_cb; |
2235 | invoke_cb = invoke_pending_cb; |
2217 | } |
2236 | } |
2218 | |
2237 | |
2219 | void |
2238 | void |
2220 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) EV_THROW |
2239 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW |
2221 | { |
2240 | { |
2222 | release_cb = release; |
2241 | release_cb = release; |
2223 | acquire_cb = acquire; |
2242 | acquire_cb = acquire; |
2224 | } |
2243 | } |
2225 | #endif |
2244 | #endif |
… | |
… | |
2319 | } |
2338 | } |
2320 | } |
2339 | } |
2321 | |
2340 | |
2322 | /* free up a loop structure */ |
2341 | /* free up a loop structure */ |
2323 | void ecb_cold |
2342 | void ecb_cold |
2324 | ev_loop_destroy (EV_P) EV_THROW |
2343 | ev_loop_destroy (EV_P) |
2325 | { |
2344 | { |
2326 | int i; |
2345 | int i; |
2327 | |
2346 | |
2328 | #if EV_MULTIPLICITY |
2347 | #if EV_MULTIPLICITY |
2329 | /* mimic free (0) */ |
2348 | /* mimic free (0) */ |
… | |
… | |
2545 | void ecb_cold |
2564 | void ecb_cold |
2546 | ev_verify (EV_P) EV_THROW |
2565 | ev_verify (EV_P) EV_THROW |
2547 | { |
2566 | { |
2548 | #if EV_VERIFY |
2567 | #if EV_VERIFY |
2549 | int i; |
2568 | int i; |
2550 | WL w; |
2569 | WL w, w2; |
2551 | |
2570 | |
2552 | assert (activecnt >= -1); |
2571 | assert (activecnt >= -1); |
2553 | |
2572 | |
2554 | assert (fdchangemax >= fdchangecnt); |
2573 | assert (fdchangemax >= fdchangecnt); |
2555 | for (i = 0; i < fdchangecnt; ++i) |
2574 | for (i = 0; i < fdchangecnt; ++i) |
2556 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2575 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2557 | |
2576 | |
2558 | assert (anfdmax >= 0); |
2577 | assert (anfdmax >= 0); |
2559 | for (i = 0; i < anfdmax; ++i) |
2578 | for (i = 0; i < anfdmax; ++i) |
|
|
2579 | { |
|
|
2580 | int j = 0; |
|
|
2581 | |
2560 | for (w = anfds [i].head; w; w = w->next) |
2582 | for (w = w2 = anfds [i].head; w; w = w->next) |
2561 | { |
2583 | { |
2562 | verify_watcher (EV_A_ (W)w); |
2584 | verify_watcher (EV_A_ (W)w); |
|
|
2585 | |
|
|
2586 | if (j++ & 1) |
|
|
2587 | { |
|
|
2588 | assert (("libev: io watcher list contains a loop", w != w2)); |
|
|
2589 | w2 = w2->next; |
|
|
2590 | } |
|
|
2591 | |
2563 | assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); |
2592 | assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); |
2564 | assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); |
2593 | assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); |
2565 | } |
2594 | } |
|
|
2595 | } |
2566 | |
2596 | |
2567 | assert (timermax >= timercnt); |
2597 | assert (timermax >= timercnt); |
2568 | verify_heap (EV_A_ timers, timercnt); |
2598 | verify_heap (EV_A_ timers, timercnt); |
2569 | |
2599 | |
2570 | #if EV_PERIODIC_ENABLE |
2600 | #if EV_PERIODIC_ENABLE |
… | |
… | |
2677 | } |
2707 | } |
2678 | |
2708 | |
2679 | void noinline |
2709 | void noinline |
2680 | ev_invoke_pending (EV_P) |
2710 | ev_invoke_pending (EV_P) |
2681 | { |
2711 | { |
2682 | int pri; |
2712 | for (pendingpri = NUMPRI; pendingpri--; ) /* pendingpri is modified during the loop */ |
2683 | |
|
|
2684 | for (pri = NUMPRI; pri--; ) |
|
|
2685 | while (pendingcnt [pri]) |
2713 | while (pendingcnt [pendingpri]) |
2686 | { |
2714 | { |
2687 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
2715 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
2688 | |
2716 | |
2689 | p->w->pending = 0; |
2717 | p->w->pending = 0; |
2690 | EV_CB_INVOKE (p->w, p->events); |
2718 | EV_CB_INVOKE (p->w, p->events); |
2691 | EV_FREQUENT_CHECK; |
2719 | EV_FREQUENT_CHECK; |
2692 | } |
2720 | } |
… | |
… | |
3241 | EV_FREQUENT_CHECK; |
3269 | EV_FREQUENT_CHECK; |
3242 | |
3270 | |
3243 | ev_start (EV_A_ (W)w, 1); |
3271 | ev_start (EV_A_ (W)w, 1); |
3244 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3272 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3245 | wlist_add (&anfds[fd].head, (WL)w); |
3273 | wlist_add (&anfds[fd].head, (WL)w); |
|
|
3274 | |
|
|
3275 | /* common bug, apparently */ |
|
|
3276 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3246 | |
3277 | |
3247 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3278 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3248 | w->events &= ~EV__IOFDSET; |
3279 | w->events &= ~EV__IOFDSET; |
3249 | |
3280 | |
3250 | EV_FREQUENT_CHECK; |
3281 | EV_FREQUENT_CHECK; |