From 5be7b524223c2fcd2286d4d46baab1554076eaf6 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Tue, 24 Jul 2018 23:02:36 +0200 Subject: [PATCH] Fix LFBTextBuffer GetChar starting worker thread when paused. --- kernel/lfbtextbuffer.cpp | 11 ++++++++--- kernel/lfbtextbuffer.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/kernel/lfbtextbuffer.cpp b/kernel/lfbtextbuffer.cpp index 167e7a10..e2040488 100644 --- a/kernel/lfbtextbuffer.cpp +++ b/kernel/lfbtextbuffer.cpp @@ -348,7 +348,7 @@ void LFBTextBuffer::RenderRange(TextPos from, TextPos to) } } -void LFBTextBuffer::IssueCommand(TextBufferCmd* cmd) +void LFBTextBuffer::IssueCommand(TextBufferCmd* cmd, bool already_locked) { if ( invalidated ) { @@ -369,12 +369,15 @@ void LFBTextBuffer::IssueCommand(TextBufferCmd* cmd) RenderRange(render_from, render_to); return; } - ScopedLock lock(&queue_lock); + if ( !already_locked ) + kthread_mutex_lock(&queue_lock); while ( queue_used == queue_length ) kthread_cond_wait(&queue_not_full, &queue_lock); if ( !queue_used ) kthread_cond_signal(&queue_not_empty); queue[(queue_offset + queue_used++) % queue_length] = *cmd; + if ( !already_locked ) + kthread_mutex_unlock(&queue_lock); } bool LFBTextBuffer::StopRendering() @@ -383,8 +386,10 @@ bool LFBTextBuffer::StopRendering() return false; TextBufferCmd cmd; cmd.type = TEXTBUFCMD_PAUSE; - IssueCommand(&cmd); ScopedLock lock(&queue_lock); + if ( queue_is_paused ) + return false; + IssueCommand(&cmd, true); while ( !queue_is_paused ) kthread_cond_wait(&queue_paused, &queue_lock); return true; diff --git a/kernel/lfbtextbuffer.h b/kernel/lfbtextbuffer.h index d2953cf1..71ec324e 100644 --- a/kernel/lfbtextbuffer.h +++ b/kernel/lfbtextbuffer.h @@ -98,7 +98,7 @@ private: void DoScroll(ssize_t off, TextChar entry); void DoMove(TextPos to, TextPos from, size_t numchars); void DoFill(TextPos from, TextPos to, TextChar fillwith); - void IssueCommand(TextBufferCmd* cmd); + void IssueCommand(TextBufferCmd* cmd, bool already_locked = false); bool StopRendering(); void ResumeRendering(); bool IsCommandIdempotent(const TextBufferCmd* cmd) const;