From 730dc9d2f928c327f14f9f6db0a0f3e5de92e677 Mon Sep 17 00:00:00 2001 From: Bob Chen Date: Mon, 29 Apr 2024 16:54:32 +0800 Subject: [PATCH] revert epoll_wait wait 0 (#472) --- io/epoll.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/io/epoll.cpp b/io/epoll.cpp index 44296fed..e6a93dca 100644 --- a/io/epoll.cpp +++ b/io/epoll.cpp @@ -203,8 +203,12 @@ ok: entry.interests |= eint; int do_epoll_wait(uint64_t timeout) { assert(_events_remain == 0); uint8_t cool_down_ms = 1; - // The granularity of epoll_wait is milliseconds, but epoll_wait 0 finishes in microseconds - timeout /= 1000; + // since timeout may less than 1ms + // in such condition, timeout_ms should be at least 1 + // or it may call epoll_wait without any idle + timeout = (timeout && timeout < 1024) ? 1 : timeout / 1024; + // make sure less than INT32_MAX + timeout &= 0x7fffffff; while (_engine_fd > 0) { int ret = epoll_wait(_engine_fd, _events, LEN(_events), timeout); if (ret < 0) {