… | |
… | |
359 | #endif |
359 | #endif |
360 | |
360 | |
361 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
361 | /* 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. */ |
362 | /* which makes programs even slower. might work on other unices, too. */ |
363 | #if EV_USE_CLOCK_SYSCALL |
363 | #if EV_USE_CLOCK_SYSCALL |
364 | # include <syscall.h> |
364 | # include <sys/syscall.h> |
365 | # ifdef SYS_clock_gettime |
365 | # ifdef SYS_clock_gettime |
366 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
366 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
367 | # undef EV_USE_MONOTONIC |
367 | # undef EV_USE_MONOTONIC |
368 | # define EV_USE_MONOTONIC 1 |
368 | # define EV_USE_MONOTONIC 1 |
369 | # else |
369 | # else |
… | |
… | |
1430 | w_->pending = ++pendingcnt [pri]; |
1430 | w_->pending = ++pendingcnt [pri]; |
1431 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1431 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1432 | pendings [pri][w_->pending - 1].w = w_; |
1432 | pendings [pri][w_->pending - 1].w = w_; |
1433 | pendings [pri][w_->pending - 1].events = revents; |
1433 | pendings [pri][w_->pending - 1].events = revents; |
1434 | } |
1434 | } |
|
|
1435 | |
|
|
1436 | pendingpri = NUMPRI - 1; |
1435 | } |
1437 | } |
1436 | |
1438 | |
1437 | inline_speed void |
1439 | inline_speed void |
1438 | feed_reverse (EV_P_ W w) |
1440 | feed_reverse (EV_P_ W w) |
1439 | { |
1441 | { |
… | |
… | |
1844 | } |
1846 | } |
1845 | |
1847 | |
1846 | inline_speed void |
1848 | inline_speed void |
1847 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1849 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1848 | { |
1850 | { |
|
|
1851 | ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ |
|
|
1852 | |
1849 | if (expect_true (*flag)) |
1853 | if (expect_true (*flag)) |
1850 | return; |
1854 | return; |
1851 | |
1855 | |
1852 | *flag = 1; |
1856 | *flag = 1; |
1853 | |
1857 | |
… | |
… | |
1872 | write (evfd, &counter, sizeof (uint64_t)); |
1876 | write (evfd, &counter, sizeof (uint64_t)); |
1873 | } |
1877 | } |
1874 | else |
1878 | else |
1875 | #endif |
1879 | #endif |
1876 | { |
1880 | { |
1877 | /* win32 people keep sending patches that change this write() to send() */ |
1881 | #ifdef _WIN32 |
1878 | /* and then run away. but send() is wrong, it wants a socket handle on win32 */ |
1882 | WSABUF buf; |
1879 | /* so when you think this write should be a send instead, please find out */ |
1883 | DWORD sent; |
1880 | /* where your send() is from - it's definitely not the microsoft send, and */ |
1884 | buf.buf = &buf; |
1881 | /* tell me. thank you. */ |
1885 | buf.len = 1; |
1882 | /* it might be that your problem is that your environment needs EV_USE_WSASOCKET */ |
1886 | 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 */ |
1887 | #else |
1884 | write (evpipe [1], &(evpipe [1]), 1); |
1888 | write (evpipe [1], &(evpipe [1]), 1); |
|
|
1889 | #endif |
1885 | } |
1890 | } |
1886 | |
1891 | |
1887 | errno = old_errno; |
1892 | errno = old_errno; |
1888 | } |
1893 | } |
1889 | } |
1894 | } |
… | |
… | |
1904 | read (evfd, &counter, sizeof (uint64_t)); |
1909 | read (evfd, &counter, sizeof (uint64_t)); |
1905 | } |
1910 | } |
1906 | else |
1911 | else |
1907 | #endif |
1912 | #endif |
1908 | { |
1913 | { |
1909 | char dummy; |
1914 | char dummy[4]; |
1910 | /* see discussion in evpipe_write when you think this read should be recv in win32 */ |
1915 | #ifdef _WIN32 |
|
|
1916 | WSABUF buf; |
|
|
1917 | DWORD recvd; |
|
|
1918 | buf.buf = dummy; |
|
|
1919 | buf.len = sizeof (dummy); |
|
|
1920 | WSARecv (EV_FD_TO_WIN32_HANDLE (evpipe [0]), &buf, 1, &recvd, 0, 0, 0); |
|
|
1921 | #else |
1911 | read (evpipe [0], &dummy, 1); |
1922 | read (evpipe [0], &dummy, sizeof (dummy)); |
|
|
1923 | #endif |
1912 | } |
1924 | } |
1913 | } |
1925 | } |
1914 | |
1926 | |
1915 | pipe_write_skipped = 0; |
1927 | pipe_write_skipped = 0; |
|
|
1928 | |
|
|
1929 | ECB_MEMORY_FENCE; /* push out skipped, acquire flags */ |
1916 | |
1930 | |
1917 | #if EV_SIGNAL_ENABLE |
1931 | #if EV_SIGNAL_ENABLE |
1918 | if (sig_pending) |
1932 | if (sig_pending) |
1919 | { |
1933 | { |
1920 | sig_pending = 0; |
1934 | sig_pending = 0; |
|
|
1935 | |
|
|
1936 | ECB_MEMORY_FENCE_RELEASE; |
1921 | |
1937 | |
1922 | for (i = EV_NSIG - 1; i--; ) |
1938 | for (i = EV_NSIG - 1; i--; ) |
1923 | if (expect_false (signals [i].pending)) |
1939 | if (expect_false (signals [i].pending)) |
1924 | ev_feed_signal_event (EV_A_ i + 1); |
1940 | ev_feed_signal_event (EV_A_ i + 1); |
1925 | } |
1941 | } |
… | |
… | |
1927 | |
1943 | |
1928 | #if EV_ASYNC_ENABLE |
1944 | #if EV_ASYNC_ENABLE |
1929 | if (async_pending) |
1945 | if (async_pending) |
1930 | { |
1946 | { |
1931 | async_pending = 0; |
1947 | async_pending = 0; |
|
|
1948 | |
|
|
1949 | ECB_MEMORY_FENCE_RELEASE; |
1932 | |
1950 | |
1933 | for (i = asynccnt; i--; ) |
1951 | for (i = asynccnt; i--; ) |
1934 | if (asyncs [i]->sent) |
1952 | if (asyncs [i]->sent) |
1935 | { |
1953 | { |
1936 | asyncs [i]->sent = 0; |
1954 | asyncs [i]->sent = 0; |
… | |
… | |
2544 | #if EV_FEATURE_API |
2562 | #if EV_FEATURE_API |
2545 | void ecb_cold |
2563 | void ecb_cold |
2546 | ev_verify (EV_P) EV_THROW |
2564 | ev_verify (EV_P) EV_THROW |
2547 | { |
2565 | { |
2548 | #if EV_VERIFY |
2566 | #if EV_VERIFY |
2549 | int i; |
2567 | int i, j; |
2550 | WL w; |
2568 | WL w, w2; |
2551 | |
2569 | |
2552 | assert (activecnt >= -1); |
2570 | assert (activecnt >= -1); |
2553 | |
2571 | |
2554 | assert (fdchangemax >= fdchangecnt); |
2572 | assert (fdchangemax >= fdchangecnt); |
2555 | for (i = 0; i < fdchangecnt; ++i) |
2573 | for (i = 0; i < fdchangecnt; ++i) |
2556 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2574 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2557 | |
2575 | |
2558 | assert (anfdmax >= 0); |
2576 | assert (anfdmax >= 0); |
2559 | for (i = 0; i < anfdmax; ++i) |
2577 | for (i = j = 0; i < anfdmax; ++i) |
2560 | for (w = anfds [i].head; w; w = w->next) |
2578 | for (w = w2 = anfds [i].head; w; w = w->next) |
2561 | { |
2579 | { |
2562 | verify_watcher (EV_A_ (W)w); |
2580 | verify_watcher (EV_A_ (W)w); |
|
|
2581 | |
|
|
2582 | if (++j & 1) |
|
|
2583 | w2 = w2->next; |
|
|
2584 | |
|
|
2585 | assert (("libev: io watcher list contains a loop", w != w2)); |
2563 | assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); |
2586 | 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)); |
2587 | assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); |
2565 | } |
2588 | } |
2566 | |
2589 | |
2567 | assert (timermax >= timercnt); |
2590 | assert (timermax >= timercnt); |
… | |
… | |
2677 | } |
2700 | } |
2678 | |
2701 | |
2679 | void noinline |
2702 | void noinline |
2680 | ev_invoke_pending (EV_P) |
2703 | ev_invoke_pending (EV_P) |
2681 | { |
2704 | { |
2682 | int pri; |
2705 | for (pendingpri = NUMPRI; pendingpri--; ) /* pendingpri is modified during the loop */ |
2683 | |
|
|
2684 | for (pri = NUMPRI; pri--; ) |
|
|
2685 | while (pendingcnt [pri]) |
2706 | while (pendingcnt [pendingpri]) |
2686 | { |
2707 | { |
2687 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
2708 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
2688 | |
2709 | |
2689 | p->w->pending = 0; |
2710 | p->w->pending = 0; |
2690 | EV_CB_INVOKE (p->w, p->events); |
2711 | EV_CB_INVOKE (p->w, p->events); |
2691 | EV_FREQUENT_CHECK; |
2712 | EV_FREQUENT_CHECK; |
2692 | } |
2713 | } |
… | |
… | |
3241 | EV_FREQUENT_CHECK; |
3262 | EV_FREQUENT_CHECK; |
3242 | |
3263 | |
3243 | ev_start (EV_A_ (W)w, 1); |
3264 | ev_start (EV_A_ (W)w, 1); |
3244 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3265 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3245 | wlist_add (&anfds[fd].head, (WL)w); |
3266 | wlist_add (&anfds[fd].head, (WL)w); |
|
|
3267 | |
|
|
3268 | /* common bug, apparently */ |
|
|
3269 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3246 | |
3270 | |
3247 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3271 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3248 | w->events &= ~EV__IOFDSET; |
3272 | w->events &= ~EV__IOFDSET; |
3249 | |
3273 | |
3250 | EV_FREQUENT_CHECK; |
3274 | EV_FREQUENT_CHECK; |