From 0c3a93efe3f4276980114501d8fe442f95112c2b Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Tue, 12 May 2026 20:47:41 +0200 Subject: [PATCH] timeouts: sys_check_timeouts: return wait time for next loop see patch #10133 So that can do: void my_loop() { long timeout; while (1) { timeout = sys_check_timeouts(); if (timeout == SYS_TIMEOUTS_SLEEPTIME_INFINITE) timeout = 100; WaitForEvent(timeout); } } Signed-off-by: Simon Goldschmidt --- src/core/timeouts.c | 11 ++++++++--- src/include/lwip/timeouts.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core/timeouts.c b/src/core/timeouts.c index 91657eb7..7baf69d2 100644 --- a/src/core/timeouts.c +++ b/src/core/timeouts.c @@ -347,8 +347,11 @@ sys_untimeout(sys_timeout_handler handler, void *arg) * handler functions when timeouts expire. * * Must be called periodically from your main loop. + * + * @return the time left before the next timeout is due. If no timeouts are + * enqueued, returns 0xffffffff */ -void +u32_t sys_check_timeouts(void) { u32_t now; @@ -367,11 +370,13 @@ sys_check_timeouts(void) tmptimeout = next_timeout; if (tmptimeout == NULL) { - return; + return SYS_TIMEOUTS_SLEEPTIME_INFINITE; } if (TIME_LESS_THAN(now, tmptimeout->time)) { - return; + u32_t ret = (u32_t)(tmptimeout->time - now); + LWIP_ASSERT("invalid sleeptime", ret <= LWIP_MAX_TIMEOUT); + return ret; } /* Timeout has expired */ diff --git a/src/include/lwip/timeouts.h b/src/include/lwip/timeouts.h index b601f9eb..234f1b31 100644 --- a/src/include/lwip/timeouts.h +++ b/src/include/lwip/timeouts.h @@ -111,7 +111,7 @@ void sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg); void sys_untimeout(sys_timeout_handler handler, void *arg); void sys_restart_timeouts(void); -void sys_check_timeouts(void); +u32_t sys_check_timeouts(void); u32_t sys_timeouts_sleeptime(void); #if LWIP_TESTMODE