mach: Fix bogus negative return

One can be very unlucky to call time_now first just before a second switch,
and mach_msg sleep just a bit more enough for the second time_now call to
count one second too many (or even more if scheduling is really unlucky).

So we have to protect against returning a bogus negative value in such case.
This commit is contained in:
Samuel Thibault 2024-08-25 03:35:29 +02:00
parent 82b5340ebd
commit f071795d80

View File

@ -43,6 +43,9 @@ __sleep (unsigned int seconds)
after = time_now (); after = time_now ();
__mach_port_destroy (__mach_task_self (), recv); __mach_port_destroy (__mach_task_self (), recv);
if (after - before > seconds)
return 0;
return seconds - (after - before); return seconds - (after - before);
} }
weak_alias (__sleep, sleep) weak_alias (__sleep, sleep)