forked from Bananymous/banan-os
Kernel: Cleanup sys_sleep() and TTY::read_impl
This commit is contained in:
parent
1ac831d4b1
commit
deeb6d2756
|
@ -598,14 +598,16 @@ namespace Kernel
|
|||
|
||||
BAN::ErrorOr<long> Process::sys_sleep(int seconds)
|
||||
{
|
||||
// FIXME: this is very dumb
|
||||
if (seconds == 0)
|
||||
return 0;
|
||||
|
||||
uint64_t wake_time = SystemTimer::get().ms_since_boot() + seconds * 1000;
|
||||
while (SystemTimer::get().ms_since_boot() < wake_time)
|
||||
{
|
||||
if (Thread::current().is_interrupted_by_signal())
|
||||
return BAN::Math::div_round_up<long>(wake_time - SystemTimer::get().ms_since_boot(), 1000);
|
||||
Scheduler::get().reschedule();
|
||||
}
|
||||
Scheduler::get().set_current_thread_sleeping(wake_time);
|
||||
|
||||
uint64_t current_time = SystemTimer::get().ms_since_boot();
|
||||
if (current_time < wake_time)
|
||||
return BAN::Math::div_round_up<long>(wake_time - current_time, 1000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -303,14 +303,12 @@ namespace Kernel
|
|||
LockGuard _(m_lock);
|
||||
while (!m_output.flush)
|
||||
{
|
||||
if (Thread::current().is_interrupted_by_signal())
|
||||
return BAN::Error::from_errno(EINTR);
|
||||
m_lock.unlock();
|
||||
m_output.semaphore.block();
|
||||
bool eintr = Thread::current().block_or_eintr(m_output.semaphore);
|
||||
m_lock.lock();
|
||||
}
|
||||
if (Thread::current().is_interrupted_by_signal())
|
||||
if (eintr)
|
||||
return BAN::Error::from_errno(EINTR);
|
||||
}
|
||||
|
||||
if (m_output.bytes == 0)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue