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:
@@ -105,7 +105,7 @@ namespace Kernel
|
|||||||
protected:
|
protected:
|
||||||
Mutex m_mutex;
|
Mutex m_mutex;
|
||||||
|
|
||||||
RecursiveSpinLock m_write_lock;
|
Mutex m_write_lock;
|
||||||
ThreadBlocker m_write_blocker;
|
ThreadBlocker m_write_blocker;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -424,7 +424,7 @@ namespace Kernel
|
|||||||
|
|
||||||
const auto termios = get_termios();
|
const auto termios = get_termios();
|
||||||
|
|
||||||
SpinLockGuard _1(m_write_lock);
|
LockGuard _(m_write_lock);
|
||||||
if (termios.c_oflag & OPOST)
|
if (termios.c_oflag & OPOST)
|
||||||
{
|
{
|
||||||
if ((termios.c_oflag & ONLCR) && ch == NL)
|
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)
|
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())
|
while (!can_write())
|
||||||
{
|
{
|
||||||
if (master_has_closed())
|
if (master_has_closed())
|
||||||
return BAN::Error::from_errno(EIO);
|
return BAN::Error::from_errno(EIO);
|
||||||
|
TRY(Thread::current().block_or_eintr_indefinite(m_write_blocker, &m_write_lock));
|
||||||
SpinLockGuardAsMutex smutex(write_guard);
|
|
||||||
TRY(Thread::current().block_or_eintr_indefinite(m_write_blocker, &smutex));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t written = 0;
|
size_t written = 0;
|
||||||
@@ -497,7 +495,7 @@ namespace Kernel
|
|||||||
void TTY::putchar_current(uint8_t ch)
|
void TTY::putchar_current(uint8_t ch)
|
||||||
{
|
{
|
||||||
ASSERT(s_tty);
|
ASSERT(s_tty);
|
||||||
SpinLockGuard _(s_tty->m_write_lock);
|
LockGuard _(s_tty->m_write_lock);
|
||||||
s_tty->putchar(ch);
|
s_tty->putchar(ch);
|
||||||
s_tty->after_write();
|
s_tty->after_write();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ namespace Kernel
|
|||||||
|
|
||||||
void VirtualTTY::clear()
|
void VirtualTTY::clear()
|
||||||
{
|
{
|
||||||
SpinLockGuard _(m_write_lock);
|
LockGuard _(m_write_lock);
|
||||||
for (uint32_t i = 0; i < m_width * m_height; i++)
|
for (uint32_t i = 0; i < m_width * m_height; i++)
|
||||||
m_buffer[i] = { .foreground = m_foreground, .background = m_background, .codepoint = ' ' };
|
m_buffer[i] = { .foreground = m_foreground, .background = m_background, .codepoint = ' ' };
|
||||||
m_terminal_driver->clear(m_background);
|
m_terminal_driver->clear(m_background);
|
||||||
@@ -73,7 +73,7 @@ namespace Kernel
|
|||||||
return BAN::Error::from_errno(EINVAL);
|
return BAN::Error::from_errno(EINVAL);
|
||||||
|
|
||||||
{
|
{
|
||||||
SpinLockGuard _(m_write_lock);
|
LockGuard _(m_write_lock);
|
||||||
|
|
||||||
TRY(m_terminal_driver->set_font(BAN::move(font)));
|
TRY(m_terminal_driver->set_font(BAN::move(font)));
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ namespace Kernel
|
|||||||
|
|
||||||
void VirtualTTY::reset_ansi()
|
void VirtualTTY::reset_ansi()
|
||||||
{
|
{
|
||||||
ASSERT(m_write_lock.current_processor_has_lock());
|
ASSERT(m_write_lock.is_locked_by_current_thread());
|
||||||
m_ansi_state = {
|
m_ansi_state = {
|
||||||
.nums = { -1, -1, -1, -1, -1 },
|
.nums = { -1, -1, -1, -1, -1 },
|
||||||
.index = 0,
|
.index = 0,
|
||||||
@@ -121,7 +121,7 @@ namespace Kernel
|
|||||||
|
|
||||||
void VirtualTTY::handle_ansi_csi_color(uint8_t value)
|
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)
|
switch (value)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@@ -201,7 +201,7 @@ namespace Kernel
|
|||||||
|
|
||||||
void VirtualTTY::handle_ansi_csi(uint8_t ch)
|
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)
|
switch (ch)
|
||||||
{
|
{
|
||||||
case '0': case '1': case '2': case '3': case '4':
|
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)
|
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);
|
ASSERT(x < m_width && y < m_height);
|
||||||
const auto& cell = m_buffer[y * m_width + x];
|
const auto& cell = m_buffer[y * m_width + x];
|
||||||
m_terminal_driver->putchar_at(cell.codepoint, x, y, cell.foreground, cell.background);
|
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)
|
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);
|
ASSERT(x < m_width && y < m_height);
|
||||||
auto& cell = m_buffer[y * m_width + x];
|
auto& cell = m_buffer[y * m_width + x];
|
||||||
cell.codepoint = codepoint;
|
cell.codepoint = codepoint;
|
||||||
@@ -488,7 +488,7 @@ namespace Kernel
|
|||||||
|
|
||||||
void VirtualTTY::putcodepoint(uint32_t codepoint)
|
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)
|
switch (codepoint)
|
||||||
{
|
{
|
||||||
@@ -534,7 +534,7 @@ namespace Kernel
|
|||||||
|
|
||||||
bool VirtualTTY::putchar_impl(uint8_t ch)
|
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;
|
uint32_t codepoint = ch;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user