You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/11/04 18:19:08 UTC
[incubator-nuttx] 02/02: libs/libc/wqueue/work_usrthread.c: Correct
time calculation in work_process
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 7e9e8a817de9c9c9e923a5c16f029e392f83444c
Author: Jukka Laitinen <ju...@ssrc.tii.ae>
AuthorDate: Wed Nov 3 10:41:01 2021 +0200
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 <ju...@ssrc.tii.ae>
---
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 3e56ea4..41831f2 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);
}