diff options
author | Conrad Pankoff <deoxxa@fknsrs.biz> | 2019-08-12 21:32:28 +1000 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-08-12 14:15:24 +0200 |
commit | 4b44962e030f6e3abf6bfc82fbf8382884d92504 (patch) | |
tree | 95f91b8a15ccc303369a6a935bba687e93288227 /Kernel | |
parent | ce8387d1ed001aae593c934e1119705525b51d85 (diff) | |
download | serenity-4b44962e030f6e3abf6bfc82fbf8382884d92504.zip |
Kernel: Use a CircularQueue for input rather than a DoubleBuffer
TTY::emit is called from an IRQ handler, and is used to push input data
into a buffer for later retrieval. Previously this was using DoubleBuffer,
but that class wants to take a lock. Our lock code wants to make sure
interrupts are enabled, but they're disabled while an IRQ handler is
running. This made the kernel sad, but this CircularQueue cheers it up by
avoiding the lock requirement completely.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/TTY/TTY.cpp | 12 | ||||
-rw-r--r-- | Kernel/TTY/TTY.h | 3 |
2 files changed, 11 insertions, 4 deletions
diff --git a/Kernel/TTY/TTY.cpp b/Kernel/TTY/TTY.cpp index f2062b6303..5a9acc4f40 100644 --- a/Kernel/TTY/TTY.cpp +++ b/Kernel/TTY/TTY.cpp @@ -26,7 +26,13 @@ void TTY::set_default_termios() ssize_t TTY::read(FileDescription&, u8* buffer, ssize_t size) { - return m_buffer.read(buffer, size); + if (m_input_buffer.size() < size) + size = m_input_buffer.size(); + + for (int i = 0; i < size; i++) + buffer[i] = m_input_buffer.dequeue(); + + return size; } ssize_t TTY::write(FileDescription&, const u8* buffer, ssize_t size) @@ -44,7 +50,7 @@ ssize_t TTY::write(FileDescription&, const u8* buffer, ssize_t size) bool TTY::can_read(FileDescription&) const { - return !m_buffer.is_empty(); + return !m_input_buffer.is_empty(); } bool TTY::can_write(FileDescription&) const @@ -71,7 +77,7 @@ void TTY::emit(u8 ch) return; } } - m_buffer.write(&ch, 1); + m_input_buffer.enqueue(ch); } void TTY::generate_signal(int signal) diff --git a/Kernel/TTY/TTY.h b/Kernel/TTY/TTY.h index 97fd9900c8..c4a23a1adb 100644 --- a/Kernel/TTY/TTY.h +++ b/Kernel/TTY/TTY.h @@ -1,6 +1,7 @@ #pragma once #include "DoubleBuffer.h" +#include <AK/CircularQueue.h> #include <Kernel/Devices/CharacterDevice.h> #include <Kernel/UnixTypes.h> @@ -46,7 +47,7 @@ private: // ^CharacterDevice virtual bool is_tty() const final override { return true; } - DoubleBuffer m_buffer; + CircularQueue<u8, 16> m_input_buffer; pid_t m_pgid { 0 }; termios m_termios; unsigned short m_rows { 0 }; |