From 7e9e8a817de9c9c9e923a5c16f029e392f83444c Mon Sep 17 00:00:00 2001 From: Jukka Laitinen Date: Wed, 3 Nov 2021 10:41:01 +0200 Subject: [PATCH] libs/libc/wqueue/work_usrthread.c: Correct time calculation in work_process This fixes busylooping in work_usrthread, due to incorrect time spec given to sem_timedwait _SEM_TIMEDWAIT works on absolute time stamps, using CLOCK_REALTIME Signed-off-by: Jukka Laitinen --- libs/libc/wqueue/work_usrthread.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/libc/wqueue/work_usrthread.c b/libs/libc/wqueue/work_usrthread.c index 3e56ea460d..41831f2d07 100644 --- a/libs/libc/wqueue/work_usrthread.c +++ b/libs/libc/wqueue/work_usrthread.c @@ -191,17 +191,18 @@ static void work_process(FAR struct usr_wqueue_s *wqueue) } else { + struct timespec now; + struct timespec delay; struct timespec rqtp; - time_t sec; /* Wait awhile to check the work list. We will wait here until * either the time elapses or until we are awakened by a semaphore. * Interrupts will be re-enabled while we wait. */ - sec = next / 1000000; - rqtp.tv_sec = sec; - rqtp.tv_nsec = (next - (sec * 1000000)) * 1000; + clock_gettime(CLOCK_REALTIME, &now); + clock_ticks2time(next, &delay); + clock_timespec_add(&now, &delay, &rqtp); _SEM_TIMEDWAIT(&wqueue->wake, &rqtp); }