From c69655e3bd0b876408c160c369f39120f71c2038 Mon Sep 17 00:00:00 2001 From: Daniel Béreš Date: Fri, 22 Apr 2022 08:06:17 +0000 Subject: libmemif: timer causes spin at 100% cpu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case of timer is set and expires: 1. timer_fd is readable and stay readable. 2. timer_fd is part of epoll_fd set. This makes epoll_pwait() calls return immediately instead of sleeping. Type: fix Signed-off-by: Daniel Béreš Change-Id: I9b228464fe45b83def9b182c885d6febf428049c --- extras/libmemif/src/main.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'extras/libmemif') diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c index 397c2bbce0c..21b39947260 100644 --- a/extras/libmemif/src/main.c +++ b/extras/libmemif/src/main.c @@ -409,6 +409,16 @@ memif_connect_handler (memif_fd_event_type_t type, void *private_ctx) memif_socket_t *ms = (memif_socket_t *) private_ctx; memif_connection_t *c; + if (ms->timer_fd >= 0) + { + uint64_t u64; + /* + Have to read the timer fd else it stays read-ready + and makes epoll_pwait() return without sleeping + */ + read (ms->timer_fd, &u64, sizeof (u64)); + } + /* loop ms->slave_interfaces and request connection for disconnected ones */ TAILQ_FOREACH (c, &ms->slave_interfaces, next) { -- cgit 1.2.3-korg