mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 18:55:07 +00:00
Kernel: Make Thread::Blocker::m_thread a NonnullRefPtr<Thread>
There's no harm in the blocker always knowing which thread it originated from. It also simplifies some logic since we don't need to think about it ever being null.
This commit is contained in:
parent
c351945474
commit
a58c4bbcf5
2 changed files with 10 additions and 15 deletions
|
@ -346,7 +346,10 @@ public:
|
||||||
BlockResult end_blocking(Badge<Thread>, bool);
|
BlockResult end_blocking(Badge<Thread>, bool);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Blocker() { }
|
Blocker()
|
||||||
|
: m_thread(*Thread::current())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void do_set_interrupted_by_death()
|
void do_set_interrupted_by_death()
|
||||||
{
|
{
|
||||||
|
@ -371,19 +374,14 @@ public:
|
||||||
}
|
}
|
||||||
void unblock_from_blocker()
|
void unblock_from_blocker()
|
||||||
{
|
{
|
||||||
RefPtr<Thread> thread;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
SpinlockLocker lock(m_lock);
|
SpinlockLocker lock(m_lock);
|
||||||
if (m_is_blocking) {
|
if (!m_is_blocking)
|
||||||
|
return;
|
||||||
m_is_blocking = false;
|
m_is_blocking = false;
|
||||||
VERIFY(m_blocked_thread);
|
|
||||||
thread = m_blocked_thread;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thread)
|
m_thread->unblock_from_blocker(*this);
|
||||||
thread->unblock_from_blocker(*this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool add_to_blocker_set(BlockerSet&, void* = nullptr);
|
bool add_to_blocker_set(BlockerSet&, void* = nullptr);
|
||||||
|
@ -393,7 +391,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BlockerSet* m_blocker_set { nullptr };
|
BlockerSet* m_blocker_set { nullptr };
|
||||||
Thread* m_blocked_thread { nullptr };
|
NonnullRefPtr<Thread> m_thread;
|
||||||
u8 m_was_interrupted_by_signal { 0 };
|
u8 m_was_interrupted_by_signal { 0 };
|
||||||
bool m_is_blocking { false };
|
bool m_is_blocking { false };
|
||||||
bool m_was_interrupted_by_death { false };
|
bool m_was_interrupted_by_death { false };
|
||||||
|
|
|
@ -49,8 +49,6 @@ void Thread::Blocker::begin_blocking(Badge<Thread>)
|
||||||
{
|
{
|
||||||
SpinlockLocker lock(m_lock);
|
SpinlockLocker lock(m_lock);
|
||||||
VERIFY(!m_is_blocking);
|
VERIFY(!m_is_blocking);
|
||||||
VERIFY(!m_blocked_thread);
|
|
||||||
m_blocked_thread = Thread::current();
|
|
||||||
m_is_blocking = true;
|
m_is_blocking = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,9 +58,8 @@ auto Thread::Blocker::end_blocking(Badge<Thread>, bool did_timeout) -> BlockResu
|
||||||
// if m_is_blocking is false here, some thread forced to
|
// if m_is_blocking is false here, some thread forced to
|
||||||
// unblock us when we get here. This is only called from the
|
// unblock us when we get here. This is only called from the
|
||||||
// thread that was blocked.
|
// thread that was blocked.
|
||||||
VERIFY(Thread::current() == m_blocked_thread);
|
VERIFY(Thread::current() == m_thread);
|
||||||
m_is_blocking = false;
|
m_is_blocking = false;
|
||||||
m_blocked_thread = nullptr;
|
|
||||||
|
|
||||||
was_unblocked(did_timeout);
|
was_unblocked(did_timeout);
|
||||||
return block_result();
|
return block_result();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue