Skip to content

Commit

Permalink
syscalls: make nsleep handle unslept time correctly
Browse files Browse the repository at this point in the history
JIRA: RTOS-977
  • Loading branch information
adamdebek committed Nov 13, 2024
1 parent dbbddd8 commit 429a28f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ int syscalls_nsleep(void *ustack)
process_t *proc = proc_current()->process;
time_t *sec;
long int *nsec;
time_t start, us, stop, diff;
time_t start, us, stop, elapsed, unslept;
int ret;

GETFROMSTACK(ustack, time_t *, sec, 0);
Expand Down Expand Up @@ -360,10 +360,15 @@ int syscalls_nsleep(void *ustack)

if (ret == -EINTR) {
proc_gettime(&stop, NULL);
diff = stop - start;
if (diff < us) {
*sec = diff / (1000 * 1000);
*nsec = (diff % (1000 * 1000)) * 1000;
elapsed = stop - start;
unslept = us - elapsed;
if ((long long)unslept <= 0) {
*sec = 0;
*nsec = 0;
}
else if (unslept < us) {
*sec = unslept / (1000 * 1000);
*nsec = (unslept % (1000 * 1000)) * 1000;
}
}

Expand Down

0 comments on commit 429a28f

Please sign in to comment.