kernel: Fix 0-delay sleeps blocking the thread forever

This commit is contained in:
apio 2023-06-08 19:57:38 +02:00
parent 85896214ba
commit d0b65674e6
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 4 additions and 1 deletions

View File

@ -6,6 +6,9 @@ Result<u64> sys_usleep(Registers*, SyscallArgs args)
{
useconds_t us = (useconds_t)args[0];
// FIXME: Allow usleep() to use a more precise resolution.
if (us < 1000) return 0;
kernel_sleep(us / 1000);
return 0;

View File

@ -271,7 +271,7 @@ namespace Scheduler
{
if (thread->state == ThreadState::Sleeping)
{
if (--thread->sleep_ticks_left == 0) thread->wake_up();
if (thread->sleep_ticks_left == 0 || --thread->sleep_ticks_left == 0) thread->wake_up();
}
}