From ed1fc7a42f75ae2134187cd6c12b3f895dc0e608 Mon Sep 17 00:00:00 2001 From: Marc Alexander Lehmann Date: Thu, 11 Jul 2019 05:41:39 +0000 Subject: [PATCH] *** empty log message *** --- Changes | 6 +++++- ev.c | 22 ++++++++++++---------- ev_epoll.c | 2 +- ev_poll.c | 2 +- ev_win32.c | 4 ++-- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Changes b/Changes index e7f25e7..9973a39 100644 --- a/Changes +++ b/Changes @@ -2,20 +2,24 @@ Revision history for libev, a high-performance and full-featured event loop. TODO: revisit 59.x timer in the light of modern powersaving TODO: maybe use timerfd to detect time jumps on linux +TODO: document EV_TSTAMP_T - linuxaio backend resulted in random memory corruption when loop is forked. - linuxaio backend might have tried to cancel an iocb multiple times (was unable to trigger this). - linuxaio backend now employs a generation counter to - avoid handlign spurious events from cancelled requests. + avoid handling spurious events from cancelled requests. - io_cancel can return EINTR, deal with it. also, assume io_submit also returns EINTR. - fix some other minor bugs in linuxaio backend. + - ev_tstamp type can now be overriden by defining EV_TSTAMP_T. - cleanup: replace expect_true/false and noinline by their libecb counterparts. - move syscall infrastructure from ev_linuxaio.c to ev.c. - prepare io_uring integration. - tweak ev_floor. + - epoll, poll, win32 Sleep and other places that use millisecond + reslution now all try to round up times. 4.27 Thu Jun 27 22:43:44 CEST 2019 - linux aio backend almost completely rewritten to work around its diff --git a/ev.c b/ev.c index f978b05..bf42d6d 100644 --- a/ev.c +++ b/ev.c @@ -546,10 +546,12 @@ struct signalfd_siginfo : 0 < (time_t)4294967295 ? 4294967295. \ : 2147483647.) \ +#define EV_TS_TO_MS(a) a * 1e3 + 0.9999 +#define EV_TS_FROM_US(us) us * 1e-6 #define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0) #define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0) -#define EV_TV_GET(tv) ((tv).tv_sec + (tv).tv_usec * 1e6) -#define EV_TS_GET(ts) ((ts).tv_sec + (ts).tv_nsec * 1e9) +#define EV_TV_GET(tv) ((tv).tv_sec + (tv).tv_usec * 1e-6) +#define EV_TS_GET(ts) ((ts).tv_sec + (ts).tv_nsec * 1e-9) /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ /* ECB.H BEGIN */ @@ -2043,7 +2045,7 @@ ev_sleep (ev_tstamp delay) EV_NOEXCEPT #elif defined _WIN32 /* maybe this should round up, as ms is very low resolution */ /* compared to select (µs) or nanosleep (ns) */ - Sleep ((unsigned long)(delay * 1e3)); + Sleep ((unsigned long)(EV_TS_TO_MS (delay))); #else struct timeval tv; @@ -2403,16 +2405,16 @@ downheap (ANHE *heap, int N, int k) if (ecb_expect_true (pos + DHEAP - 1 < E)) { /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); - if ( ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); - if ( ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos)); - if ( ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos)); + if ( minat > ANHE_at (pos [1])) (minpos = pos + 1), (minat = ANHE_at (*minpos)); + if ( minat > ANHE_at (pos [2])) (minpos = pos + 2), (minat = ANHE_at (*minpos)); + if ( minat > ANHE_at (pos [3])) (minpos = pos + 3), (minat = ANHE_at (*minpos)); } else if (pos < E) { /* slow path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); - if (pos + 1 < E && ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); - if (pos + 2 < E && ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos)); - if (pos + 3 < E && ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos)); + if (pos + 1 < E && minat > ANHE_at (pos [1])) (minpos = pos + 1), (minat = ANHE_at (*minpos)); + if (pos + 2 < E && minat > ANHE_at (pos [2])) (minpos = pos + 2), (minat = ANHE_at (*minpos)); + if (pos + 3 < E && minat > ANHE_at (pos [3])) (minpos = pos + 3), (minat = ANHE_at (*minpos)); } else break; @@ -2430,7 +2432,7 @@ downheap (ANHE *heap, int N, int k) ev_active (ANHE_w (he)) = k; } -#else /* 4HEAP */ +#else /* not 4HEAP */ #define HEAP0 1 #define HPARENT(k) ((k) >> 1) diff --git a/ev_epoll.c b/ev_epoll.c index ab6033e..1832ec8 100644 --- a/ev_epoll.c +++ b/ev_epoll.c @@ -152,7 +152,7 @@ epoll_poll (EV_P_ ev_tstamp timeout) /* epoll wait times cannot be larger than (LONG_MAX - 999UL) / HZ msecs, which is below */ /* the default libev max wait time, however. */ EV_RELEASE_CB; - eventcnt = epoll_wait (backend_fd, epoll_events, epoll_eventmax, timeout * 1e3 + 0.9999); + eventcnt = epoll_wait (backend_fd, epoll_events, epoll_eventmax, EV_TS_TO_MS (timeout)); EV_ACQUIRE_CB; if (ecb_expect_false (eventcnt < 0)) diff --git a/ev_poll.c b/ev_poll.c index 880d592..e6d3202 100644 --- a/ev_poll.c +++ b/ev_poll.c @@ -95,7 +95,7 @@ poll_poll (EV_P_ ev_tstamp timeout) int res; EV_RELEASE_CB; - res = poll (polls, pollcnt, timeout * 1e3 + 0.9999); + res = poll (polls, pollcnt, EV_TS_TO_MS (timeout)); EV_ACQUIRE_CB; if (ecb_expect_false (res < 0)) diff --git a/ev_win32.c b/ev_win32.c index fd67135..8c5bef0 100644 --- a/ev_win32.c +++ b/ev_win32.c @@ -154,8 +154,8 @@ ev_time (void) ui.u.LowPart = ft.dwLowDateTime; ui.u.HighPart = ft.dwHighDateTime; - /* msvc cannot convert ulonglong to double... yes, it is that sucky */ - return (LONGLONG)(ui.QuadPart - 116444736000000000) * 1e-7; + /* also, msvc cannot convert ulonglong to double... yes, it is that sucky */ + return EV_TS_FROM_US (((LONGLONG)(ui.QuadPart - 116444736000000000) * 1e-1)) } #endif