Kernel: Fix spurious wakeup from SYS_SLEEP

This commit is contained in:
Bananymous 2025-06-27 15:40:13 +03:00
parent fb09aa4d06
commit fe62ce4bae
1 changed files with 8 additions and 2 deletions

View File

@ -819,12 +819,18 @@ namespace Kernel
return 0; return 0;
const uint64_t wake_time_ms = SystemTimer::get().ms_since_boot() + (seconds * 1000); const uint64_t wake_time_ms = SystemTimer::get().ms_since_boot() + (seconds * 1000);
SystemTimer::get().sleep_ms(seconds * 1000);
while (!Thread::current().is_interrupted_by_signal())
{
const uint64_t current_ms = SystemTimer::get().ms_since_boot();
if (current_ms >= wake_time_ms)
break;
SystemTimer::get().sleep_ms(wake_time_ms - current_ms);
}
const uint64_t current_ms = SystemTimer::get().ms_since_boot(); const uint64_t current_ms = SystemTimer::get().ms_since_boot();
if (current_ms < wake_time_ms) if (current_ms < wake_time_ms)
return BAN::Math::div_round_up<long>(wake_time_ms - current_ms, 1000); return BAN::Math::div_round_up<long>(wake_time_ms - current_ms, 1000);
return 0; return 0;
} }