Skip to content

Commit 156c554

Browse files
committed
Kernel: Handle unblocking properly in WaitQueue
Waiter::clear() will always be called with the associated thread being the same as the current thread, so the state of the thread should then be `Running` instead of `Runnable`. If the current thread unblocked itself, then the thread is effectively running, and not just runnable.
1 parent 6634ab6 commit 156c554

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Kernel/Tasks/WaitQueue.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ void WaitQueue::notify_one()
3434
void WaitQueue::Waiter::notify(Badge<WaitQueue>)
3535
{
3636
VERIFY(m_association.has_value());
37-
SpinlockLocker scheduler_lock(g_scheduler_lock);
3837
auto& thread = *m_association->thread;
3938

39+
SpinlockLocker scheduler_lock(g_scheduler_lock);
4040
VERIFY(thread.state() == Thread::State::Blocked);
41+
VERIFY(&thread != Thread::current());
4142
thread.set_state(Thread::State::Runnable);
4243
}
4344

@@ -90,8 +91,9 @@ void WaitQueue::Waiter::clear()
9091

9192
auto& thread = *m_association->thread;
9293
SpinlockLocker scheduler_lock(g_scheduler_lock);
93-
if (thread.state() == Thread::State::Blocked)
94-
thread.set_state(Thread::State::Runnable);
94+
VERIFY(thread.state() == Thread::State::Blocked);
95+
VERIFY(&thread == Thread::current());
96+
thread.set_state(Thread::State::Running);
9597

9698
m_association = {};
9799
}

0 commit comments

Comments
 (0)