1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 15:08:12 +00:00

Kernel: Use a dedicated thread state for wait-queued threads

Instead of using the generic block mechanism, wait-queued threads now
go into the special Queued state.

This fixes an issue where signal dispatch would unblock a wait-queued
thread (because signal dispatch unblocks blocked threads) and cause
confusion since the thread only expected to be awoken by the queue.
This commit is contained in:
Andreas Kling 2019-12-01 15:54:47 +01:00
parent 7126a42d4d
commit 5859e16e53
5 changed files with 42 additions and 59 deletions

View file

@ -180,12 +180,14 @@ void Thread::yield_without_holding_big_lock()
process().big_lock().lock();
}
void Thread::donate_and_yield_without_holding_big_lock(Thread* beneficiary, const char* reason)
bool Thread::unlock_process_if_locked()
{
bool did_unlock = process().big_lock().unlock_if_locked();
Scheduler::donate_to(beneficiary, reason);
if (did_unlock)
process().big_lock().lock();
return process().big_lock().unlock_if_locked();
}
void Thread::relock_process()
{
process().big_lock().lock();
}
u64 Thread::sleep(u32 ticks)
@ -227,6 +229,8 @@ const char* Thread::state_string() const
return "Skip1";
case Thread::Skip0SchedulerPasses:
return "Skip0";
case Thread::Queued:
return "Queued";
case Thread::Blocked:
ASSERT(m_blocker != nullptr);
return m_blocker->state_string();
@ -645,6 +649,9 @@ bool Thread::is_thread(void* ptr)
void Thread::set_state(State new_state)
{
InterruptDisabler disabler;
if (new_state == m_state)
return;
if (new_state == Blocked) {
// we should always have a Blocker while blocked
ASSERT(m_blocker != nullptr);