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:
parent
4cf0859612
commit
bd73102513
3 changed files with 42 additions and 17 deletions
|
@ -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 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue