From a90b14239198996798586e07b68d4e2f71916078 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Thu, 5 Dec 2024 11:05:41 +0800 Subject: [PATCH] Manipulate the delay only when it is positive The return value of '_twin_timeout_delay' might be negative, and the polling should be aware of it; otherwise, an unbounded delay occurs. --- src/dispatch.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/dispatch.c b/src/dispatch.c index d1f8aa4..4864ab0 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -17,7 +17,9 @@ void twin_dispatch(twin_context_t *ctx) _twin_run_timeout(); _twin_run_work(); if (g_twin_backend.poll && !g_twin_backend.poll(ctx)) { - usleep(_twin_timeout_delay() * 1000); + twin_time_t delay = _twin_timeout_delay(); + if (delay > 0) + usleep(delay * 1000); break; } }