1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 14:27:31 +00:00

Kernel: Don't register thread as custom data for WaitQueueBlocker

When adding a WaitQueueBlocker to a WaitQueue, it stored the blocked
thread in the registration's custom "void* data" slot.
This was only used to print the Thread* in some debug logging.

Now that Blocker always knows its origin Thread, we can simply add
a Blocker::thread() accessor and then get the blocked Thread& from
there. No need to register custom data.
This commit is contained in:
Andreas Kling 2021-08-24 01:07:16 +02:00
parent a58c4bbcf5
commit 2c74533ba6
4 changed files with 13 additions and 15 deletions

View File

@ -301,6 +301,8 @@ public:
virtual const BlockTimeout& override_timeout(const BlockTimeout& timeout) { return timeout; }
virtual bool can_be_interrupted() const { return true; }
Thread& thread() { return m_thread; }
enum class UnblockImmediatelyReason {
UnblockConditionAlreadyMet,
TimeoutInThePast,

View File

@ -116,7 +116,7 @@ bool Thread::JoinBlocker::unblock(void* value, bool from_add_blocker)
Thread::WaitQueueBlocker::WaitQueueBlocker(WaitQueue& wait_queue, StringView block_reason)
: m_block_reason(block_reason)
{
if (!add_to_blocker_set(wait_queue, Thread::current()))
if (!add_to_blocker_set(wait_queue))
m_should_block = false;
}

View File

@ -10,17 +10,16 @@
namespace Kernel {
bool WaitQueue::should_add_blocker(Thread::Blocker& b, void* data)
bool WaitQueue::should_add_blocker(Thread::Blocker& b, void*)
{
VERIFY(data != nullptr); // Thread that is requesting to be blocked
VERIFY(m_lock.is_locked());
VERIFY(b.blocker_type() == Thread::Blocker::Type::Queue);
if (m_wake_requested) {
m_wake_requested = false;
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: do not block thread {}", this, data);
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: do not block thread {}", this, b.thread());
return false;
}
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: should block thread {}", this, data);
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: should block thread {}", this, b.thread());
return true;
}
@ -29,11 +28,10 @@ u32 WaitQueue::wake_one()
u32 did_wake = 0;
SpinlockLocker lock(m_lock);
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: wake_one", this);
bool did_unblock_one = unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void* data, bool& stop_iterating) {
VERIFY(data);
bool did_unblock_one = unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void*, bool& stop_iterating) {
VERIFY(b.blocker_type() == Thread::Blocker::Type::Queue);
auto& blocker = static_cast<Thread::WaitQueueBlocker&>(b);
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: wake_one unblocking {}", this, data);
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: wake_one unblocking {}", this, blocker.thread());
if (blocker.unblock()) {
stop_iterating = true;
did_wake = 1;
@ -54,11 +52,10 @@ u32 WaitQueue::wake_n(u32 wake_count)
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: wake_n({})", this, wake_count);
u32 did_wake = 0;
bool did_unblock_some = unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void* data, bool& stop_iterating) {
VERIFY(data);
bool did_unblock_some = unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void*, bool& stop_iterating) {
VERIFY(b.blocker_type() == Thread::Blocker::Type::Queue);
auto& blocker = static_cast<Thread::WaitQueueBlocker&>(b);
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: wake_n unblocking {}", this, data);
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: wake_n unblocking {}", this, blocker.thread());
VERIFY(did_wake < wake_count);
if (blocker.unblock()) {
if (++did_wake >= wake_count)
@ -79,12 +76,11 @@ u32 WaitQueue::wake_all()
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: wake_all", this);
u32 did_wake = 0;
bool did_unblock_any = unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void* data, bool&) {
VERIFY(data);
bool did_unblock_any = unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void*, bool&) {
VERIFY(b.blocker_type() == Thread::Blocker::Type::Queue);
auto& blocker = static_cast<Thread::WaitQueueBlocker&>(b);
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: wake_all unblocking {}", this, data);
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: wake_all unblocking {}", this, blocker.thread());
if (blocker.unblock()) {
did_wake++;

View File

@ -31,7 +31,7 @@ public:
}
protected:
virtual bool should_add_blocker(Thread::Blocker& b, void* data) override;
virtual bool should_add_blocker(Thread::Blocker& b, void*) override;
private:
bool m_wake_requested { false };