From 7c11ea3694667c73c949e184a4ae24c4aa7f5213 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 7 Sep 2023 15:27:21 +0300 Subject: [PATCH] Kernel: Cleanup TTY::read() --- kernel/kernel/Terminal/TTY.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kernel/kernel/Terminal/TTY.cpp b/kernel/kernel/Terminal/TTY.cpp index bd5839cd..472343ce 100644 --- a/kernel/kernel/Terminal/TTY.cpp +++ b/kernel/kernel/Terminal/TTY.cpp @@ -251,14 +251,20 @@ namespace Kernel BAN::ErrorOr TTY::read(size_t, void* buffer, size_t count) { - m_lock.lock(); + LockGuard _(m_lock); while (!m_output.flush) { m_lock.unlock(); m_output.semaphore.block(); m_lock.lock(); } - + + if (m_output.bytes == 0) + { + m_output.flush = false; + return 0; + } + size_t to_copy = BAN::Math::min(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; }