summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-08-24 01:07:16 +0200
committerAndreas Kling <kling@serenityos.org>2021-08-24 01:57:11 +0200
commit2c74533ba62505828b6ccf1c71db9c0c2fd3527f (patch)
tree9c20905dbdd632277cad438886abf39330ad7c84
parenta58c4bbcf50dfae2e8e7432e6728fd90ccaf80ad (diff)
downloadserenity-2c74533ba62505828b6ccf1c71db9c0c2fd3527f.zip
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.
-rw-r--r--Kernel/Thread.h2
-rw-r--r--Kernel/ThreadBlockers.cpp2
-rw-r--r--Kernel/WaitQueue.cpp22
-rw-r--r--Kernel/WaitQueue.h2
4 files changed, 13 insertions, 15 deletions
diff --git a/Kernel/Thread.h b/Kernel/Thread.h
index 3eef612e0d..50534b7b6e 100644
--- a/Kernel/Thread.h
+++ b/Kernel/Thread.h
@@ -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,
diff --git a/Kernel/ThreadBlockers.cpp b/Kernel/ThreadBlockers.cpp
index e628b69a1e..3389066100 100644
--- a/Kernel/ThreadBlockers.cpp
+++ b/Kernel/ThreadBlockers.cpp
@@ -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;
}
diff --git a/Kernel/WaitQueue.cpp b/Kernel/WaitQueue.cpp
index ebe3a53dbf..e1e2a80c06 100644
--- a/Kernel/WaitQueue.cpp
+++ b/Kernel/WaitQueue.cpp
@@ -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++;
diff --git a/Kernel/WaitQueue.h b/Kernel/WaitQueue.h
index a9e872852c..9c8ca5c83e 100644
--- a/Kernel/WaitQueue.h
+++ b/Kernel/WaitQueue.h
@@ -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 };