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 <jukkax@ssrc.tii.ae>
This commit is contained in:
Jukka Laitinen 2021-11-03 10:41:01 +02:00 committed by Xiang Xiao
parent c79d2067c7
commit 7e9e8a817d
1 changed files with 5 additions and 4 deletions

View File

@ -191,17 +191,18 @@ static void work_process(FAR struct usr_wqueue_s *wqueue)
} }
else else
{ {
struct timespec now;
struct timespec delay;
struct timespec rqtp; struct timespec rqtp;
time_t sec;
/* Wait awhile to check the work list. We will wait here until /* Wait awhile to check the work list. We will wait here until
* either the time elapses or until we are awakened by a semaphore. * either the time elapses or until we are awakened by a semaphore.
* Interrupts will be re-enabled while we wait. * Interrupts will be re-enabled while we wait.
*/ */
sec = next / 1000000; clock_gettime(CLOCK_REALTIME, &now);
rqtp.tv_sec = sec; clock_ticks2time(next, &delay);
rqtp.tv_nsec = (next - (sec * 1000000)) * 1000; clock_timespec_add(&now, &delay, &rqtp);
_SEM_TIMEDWAIT(&wqueue->wake, &rqtp); _SEM_TIMEDWAIT(&wqueue->wake, &rqtp);
} }