1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:18:13 +00:00

Kernel: Fix some race conditions with Lock and waiting/waking threads

There is a window between acquiring/releasing the lock with the atomic
variables and subsequently waiting or waking threads. With a single
processor this window was closed by using a critical section, but
this doesn't prevent other processors from running these code paths.
To solve this, set a flag in the WaitQueue while holding m_lock which
determines if threads should be blocked at all.
This commit is contained in:
Tom 2021-01-23 22:30:10 -07:00 committed by Andreas Kling
parent 4cf0859612
commit bd73102513
3 changed files with 42 additions and 17 deletions

View file

@ -34,10 +34,16 @@ namespace Kernel {
class WaitQueue : public Thread::BlockCondition {
public:
void wake_one();
u32 wake_one();
u32 wake_n(u32 wake_count);
u32 wake_all();
void should_block(bool block)
{
ScopedSpinLock lock(m_lock);
m_should_block = block;
}
template<class... Args>
Thread::BlockResult wait_on(const Thread::BlockTimeout& timeout, Args&&... args)
{
@ -49,6 +55,7 @@ protected:
private:
bool m_wake_requested { false };
bool m_should_block { true };
};
}