Преглед на файлове

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.
Andreas Kling преди 4 години
родител
ревизия
2c74533ba6
променени са 4 файла, в които са добавени 13 реда и са изтрити 15 реда
  1. 2 0
      Kernel/Thread.h
  2. 1 1
      Kernel/ThreadBlockers.cpp
  3. 9 13
      Kernel/WaitQueue.cpp
  4. 1 1
      Kernel/WaitQueue.h

+ 2 - 0
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,

+ 1 - 1
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;
 }
 

+ 9 - 13
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++;

+ 1 - 1
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 };