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)
|
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;
|
uint64_t wake_time = SystemTimer::get().ms_since_boot() + seconds * 1000;
|
||||||
while (SystemTimer::get().ms_since_boot() < wake_time)
|
Scheduler::get().set_current_thread_sleeping(wake_time);
|
||||||
{
|
|
||||||
if (Thread::current().is_interrupted_by_signal())
|
uint64_t current_time = SystemTimer::get().ms_since_boot();
|
||||||
return BAN::Math::div_round_up<long>(wake_time - SystemTimer::get().ms_since_boot(), 1000);
|
if (current_time < wake_time)
|
||||||
Scheduler::get().reschedule();
|
return BAN::Math::div_round_up<long>(wake_time - current_time, 1000);
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -303,14 +303,12 @@ namespace Kernel
|
||||||
LockGuard _(m_lock);
|
LockGuard _(m_lock);
|
||||||
while (!m_output.flush)
|
while (!m_output.flush)
|
||||||
{
|
{
|
||||||
if (Thread::current().is_interrupted_by_signal())
|
|
||||||
return BAN::Error::from_errno(EINTR);
|
|
||||||
m_lock.unlock();
|
m_lock.unlock();
|
||||||
m_output.semaphore.block();
|
bool eintr = Thread::current().block_or_eintr(m_output.semaphore);
|
||||||
m_lock.lock();
|
m_lock.lock();
|
||||||
|
if (eintr)
|
||||||
|
return BAN::Error::from_errno(EINTR);
|
||||||
}
|
}
|
||||||
if (Thread::current().is_interrupted_by_signal())
|
|
||||||
return BAN::Error::from_errno(EINTR);
|
|
||||||
|
|
||||||
if (m_output.bytes == 0)
|
if (m_output.bytes == 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue