Kernel: Cleanup TTY::read()

This commit is contained in:
Bananymous 2023-09-07 15:27:21 +03:00
parent c1fd341698
commit 7c11ea3694
1 changed files with 8 additions and 4 deletions

View File

@ -251,7 +251,7 @@ namespace Kernel
BAN::ErrorOr<size_t> TTY::read(size_t, void* buffer, size_t count)
{
m_lock.lock();
LockGuard _(m_lock);
while (!m_output.flush)
{
m_lock.unlock();
@ -259,6 +259,12 @@ namespace Kernel
m_lock.lock();
}
if (m_output.bytes == 0)
{
m_output.flush = false;
return 0;
}
size_t to_copy = BAN::Math::min<size_t>(count, m_output.bytes);
memcpy(buffer, m_output.buffer.data(), to_copy);
@ -270,8 +276,6 @@ namespace Kernel
m_output.semaphore.unblock();
m_lock.unlock();
return to_copy;
}