Kernel: Make TTY write lock a mutex instead of a spinlock

The mutex could not be locked while processing ANSI DGR in VTTY
This commit is contained in:
2026-05-16 23:52:28 +03:00
parent d081655913
commit 6e95519acc
3 changed files with 14 additions and 16 deletions

View File

@@ -105,7 +105,7 @@ namespace Kernel
protected:
Mutex m_mutex;
RecursiveSpinLock m_write_lock;
Mutex m_write_lock;
ThreadBlocker m_write_blocker;
};

View File

@@ -424,7 +424,7 @@ namespace Kernel
const auto termios = get_termios();
SpinLockGuard _1(m_write_lock);
LockGuard _(m_write_lock);
if (termios.c_oflag & OPOST)
{
if ((termios.c_oflag & ONLCR) && ch == NL)
@@ -471,15 +471,13 @@ namespace Kernel
BAN::ErrorOr<size_t> TTY::write_impl(off_t, BAN::ConstByteSpan buffer)
{
SpinLockGuard write_guard(m_write_lock);
LockGuard write_guard(m_write_lock);
while (!can_write())
{
if (master_has_closed())
return BAN::Error::from_errno(EIO);
SpinLockGuardAsMutex smutex(write_guard);
TRY(Thread::current().block_or_eintr_indefinite(m_write_blocker, &smutex));
TRY(Thread::current().block_or_eintr_indefinite(m_write_blocker, &m_write_lock));
}
size_t written = 0;
@@ -497,7 +495,7 @@ namespace Kernel
void TTY::putchar_current(uint8_t ch)
{
ASSERT(s_tty);
SpinLockGuard _(s_tty->m_write_lock);
LockGuard _(s_tty->m_write_lock);
s_tty->putchar(ch);
s_tty->after_write();
}

View File

@@ -61,7 +61,7 @@ namespace Kernel
void VirtualTTY::clear()
{
SpinLockGuard _(m_write_lock);
LockGuard _(m_write_lock);
for (uint32_t i = 0; i < m_width * m_height; i++)
m_buffer[i] = { .foreground = m_foreground, .background = m_background, .codepoint = ' ' };
m_terminal_driver->clear(m_background);
@@ -73,7 +73,7 @@ namespace Kernel
return BAN::Error::from_errno(EINVAL);
{
SpinLockGuard _(m_write_lock);
LockGuard _(m_write_lock);
TRY(m_terminal_driver->set_font(BAN::move(font)));
@@ -110,7 +110,7 @@ namespace Kernel
void VirtualTTY::reset_ansi()
{
ASSERT(m_write_lock.current_processor_has_lock());
ASSERT(m_write_lock.is_locked_by_current_thread());
m_ansi_state = {
.nums = { -1, -1, -1, -1, -1 },
.index = 0,
@@ -121,7 +121,7 @@ namespace Kernel
void VirtualTTY::handle_ansi_csi_color(uint8_t value)
{
ASSERT(m_write_lock.current_processor_has_lock());
ASSERT(m_write_lock.is_locked_by_current_thread());
switch (value)
{
case 0:
@@ -201,7 +201,7 @@ namespace Kernel
void VirtualTTY::handle_ansi_csi(uint8_t ch)
{
ASSERT(m_write_lock.current_processor_has_lock());
ASSERT(m_write_lock.is_locked_by_current_thread());
switch (ch)
{
case '0': case '1': case '2': case '3': case '4':
@@ -446,7 +446,7 @@ namespace Kernel
void VirtualTTY::render_from_buffer(uint32_t x, uint32_t y)
{
ASSERT(m_write_lock.current_processor_has_lock());
ASSERT(m_write_lock.is_locked_by_current_thread());
ASSERT(x < m_width && y < m_height);
const auto& cell = m_buffer[y * m_width + x];
m_terminal_driver->putchar_at(cell.codepoint, x, y, cell.foreground, cell.background);
@@ -454,7 +454,7 @@ namespace Kernel
void VirtualTTY::putchar_at(uint32_t codepoint, uint32_t x, uint32_t y)
{
ASSERT(m_write_lock.current_processor_has_lock());
ASSERT(m_write_lock.is_locked_by_current_thread());
ASSERT(x < m_width && y < m_height);
auto& cell = m_buffer[y * m_width + x];
cell.codepoint = codepoint;
@@ -488,7 +488,7 @@ namespace Kernel
void VirtualTTY::putcodepoint(uint32_t codepoint)
{
ASSERT(m_write_lock.current_processor_has_lock());
ASSERT(m_write_lock.is_locked_by_current_thread());
switch (codepoint)
{
@@ -534,7 +534,7 @@ namespace Kernel
bool VirtualTTY::putchar_impl(uint8_t ch)
{
ASSERT(m_write_lock.current_processor_has_lock());
ASSERT(m_write_lock.is_locked_by_current_thread());
uint32_t codepoint = ch;