… | |
… | |
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 | |
… | |
… | |
1912 | } |
1916 | } |
1913 | } |
1917 | } |
1914 | |
1918 | |
1915 | pipe_write_skipped = 0; |
1919 | pipe_write_skipped = 0; |
1916 | |
1920 | |
|
|
1921 | ECB_MEMORY_FENCE; /* push out skipped, acquire flags */ |
|
|
1922 | |
1917 | #if EV_SIGNAL_ENABLE |
1923 | #if EV_SIGNAL_ENABLE |
1918 | if (sig_pending) |
1924 | if (sig_pending) |
1919 | { |
1925 | { |
1920 | sig_pending = 0; |
1926 | sig_pending = 0; |
|
|
1927 | |
|
|
1928 | ECB_MEMORY_FENCE_RELEASE; |
1921 | |
1929 | |
1922 | for (i = EV_NSIG - 1; i--; ) |
1930 | for (i = EV_NSIG - 1; i--; ) |
1923 | if (expect_false (signals [i].pending)) |
1931 | if (expect_false (signals [i].pending)) |
1924 | ev_feed_signal_event (EV_A_ i + 1); |
1932 | ev_feed_signal_event (EV_A_ i + 1); |
1925 | } |
1933 | } |
… | |
… | |
1927 | |
1935 | |
1928 | #if EV_ASYNC_ENABLE |
1936 | #if EV_ASYNC_ENABLE |
1929 | if (async_pending) |
1937 | if (async_pending) |
1930 | { |
1938 | { |
1931 | async_pending = 0; |
1939 | async_pending = 0; |
|
|
1940 | |
|
|
1941 | ECB_MEMORY_FENCE_RELEASE; |
1932 | |
1942 | |
1933 | for (i = asynccnt; i--; ) |
1943 | for (i = asynccnt; i--; ) |
1934 | if (asyncs [i]->sent) |
1944 | if (asyncs [i]->sent) |
1935 | { |
1945 | { |
1936 | asyncs [i]->sent = 0; |
1946 | asyncs [i]->sent = 0; |
… | |
… | |
2544 | #if EV_FEATURE_API |
2554 | #if EV_FEATURE_API |
2545 | void ecb_cold |
2555 | void ecb_cold |
2546 | ev_verify (EV_P) EV_THROW |
2556 | ev_verify (EV_P) EV_THROW |
2547 | { |
2557 | { |
2548 | #if EV_VERIFY |
2558 | #if EV_VERIFY |
2549 | int i; |
2559 | int i, j; |
2550 | WL w; |
2560 | WL w, w2; |
2551 | |
2561 | |
2552 | assert (activecnt >= -1); |
2562 | assert (activecnt >= -1); |
2553 | |
2563 | |
2554 | assert (fdchangemax >= fdchangecnt); |
2564 | assert (fdchangemax >= fdchangecnt); |
2555 | for (i = 0; i < fdchangecnt; ++i) |
2565 | for (i = 0; i < fdchangecnt; ++i) |
2556 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2566 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2557 | |
2567 | |
2558 | assert (anfdmax >= 0); |
2568 | assert (anfdmax >= 0); |
2559 | for (i = 0; i < anfdmax; ++i) |
2569 | for (i = j = 0; i < anfdmax; ++i) |
2560 | for (w = anfds [i].head; w; w = w->next) |
2570 | for (w = w2 = anfds [i].head; w; w = w->next) |
2561 | { |
2571 | { |
2562 | verify_watcher (EV_A_ (W)w); |
2572 | verify_watcher (EV_A_ (W)w); |
|
|
2573 | |
|
|
2574 | if (++j & 1) |
|
|
2575 | w2 = w2->next; |
|
|
2576 | |
|
|
2577 | assert (("libev: io watcher list contains a loop", w != w2)); |
2563 | assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); |
2578 | 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)); |
2579 | assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); |
2565 | } |
2580 | } |
2566 | |
2581 | |
2567 | assert (timermax >= timercnt); |
2582 | assert (timermax >= timercnt); |
… | |
… | |
2677 | } |
2692 | } |
2678 | |
2693 | |
2679 | void noinline |
2694 | void noinline |
2680 | ev_invoke_pending (EV_P) |
2695 | ev_invoke_pending (EV_P) |
2681 | { |
2696 | { |
2682 | int pri; |
2697 | for (pendingpri = NUMPRI; pendingpri--; ) /* pendingpri is modified during the loop */ |
2683 | |
|
|
2684 | for (pri = NUMPRI; pri--; ) |
|
|
2685 | while (pendingcnt [pri]) |
2698 | while (pendingcnt [pendingpri]) |
2686 | { |
2699 | { |
2687 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
2700 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
2688 | |
2701 | |
2689 | p->w->pending = 0; |
2702 | p->w->pending = 0; |
2690 | EV_CB_INVOKE (p->w, p->events); |
2703 | EV_CB_INVOKE (p->w, p->events); |
2691 | EV_FREQUENT_CHECK; |
2704 | EV_FREQUENT_CHECK; |
2692 | } |
2705 | } |
… | |
… | |
3241 | EV_FREQUENT_CHECK; |
3254 | EV_FREQUENT_CHECK; |
3242 | |
3255 | |
3243 | ev_start (EV_A_ (W)w, 1); |
3256 | ev_start (EV_A_ (W)w, 1); |
3244 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3257 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3245 | wlist_add (&anfds[fd].head, (WL)w); |
3258 | wlist_add (&anfds[fd].head, (WL)w); |
|
|
3259 | |
|
|
3260 | /* common bug, apparently */ |
|
|
3261 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3246 | |
3262 | |
3247 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3263 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3248 | w->events &= ~EV__IOFDSET; |
3264 | w->events &= ~EV__IOFDSET; |
3249 | |
3265 | |
3250 | EV_FREQUENT_CHECK; |
3266 | EV_FREQUENT_CHECK; |