mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-23 02:55:15 +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:
parent
a58c4bbcf5
commit
2c74533ba6
|
@ -301,6 +301,8 @@ public:
|
||||||
virtual const BlockTimeout& override_timeout(const BlockTimeout& timeout) { return timeout; }
|
virtual const BlockTimeout& override_timeout(const BlockTimeout& timeout) { return timeout; }
|
||||||
virtual bool can_be_interrupted() const { return true; }
|
virtual bool can_be_interrupted() const { return true; }
|
||||||
|
|
||||||
|
Thread& thread() { return m_thread; }
|
||||||
|
|
||||||
enum class UnblockImmediatelyReason {
|
enum class UnblockImmediatelyReason {
|
||||||
UnblockConditionAlreadyMet,
|
UnblockConditionAlreadyMet,
|
||||||
TimeoutInThePast,
|
TimeoutInThePast,
|
||||||
|
|
|
@ -116,7 +116,7 @@ bool Thread::JoinBlocker::unblock(void* value, bool from_add_blocker)
|
||||||
Thread::WaitQueueBlocker::WaitQueueBlocker(WaitQueue& wait_queue, StringView block_reason)
|
Thread::WaitQueueBlocker::WaitQueueBlocker(WaitQueue& wait_queue, StringView block_reason)
|
||||||
: m_block_reason(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;
|
m_should_block = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,17 +10,16 @@
|
||||||
|
|
||||||
namespace Kernel {
|
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(m_lock.is_locked());
|
||||||
VERIFY(b.blocker_type() == Thread::Blocker::Type::Queue);
|
VERIFY(b.blocker_type() == Thread::Blocker::Type::Queue);
|
||||||
if (m_wake_requested) {
|
if (m_wake_requested) {
|
||||||
m_wake_requested = false;
|
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;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,11 +28,10 @@ u32 WaitQueue::wake_one()
|
||||||
u32 did_wake = 0;
|
u32 did_wake = 0;
|
||||||
SpinlockLocker lock(m_lock);
|
SpinlockLocker lock(m_lock);
|
||||||
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: wake_one", this);
|
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) {
|
bool did_unblock_one = unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void*, bool& stop_iterating) {
|
||||||
VERIFY(data);
|
|
||||||
VERIFY(b.blocker_type() == Thread::Blocker::Type::Queue);
|
VERIFY(b.blocker_type() == Thread::Blocker::Type::Queue);
|
||||||
auto& blocker = static_cast<Thread::WaitQueueBlocker&>(b);
|
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()) {
|
if (blocker.unblock()) {
|
||||||
stop_iterating = true;
|
stop_iterating = true;
|
||||||
did_wake = 1;
|
did_wake = 1;
|
||||||
|
@ -54,11 +52,10 @@ u32 WaitQueue::wake_n(u32 wake_count)
|
||||||
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: wake_n({})", this, wake_count);
|
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: wake_n({})", this, wake_count);
|
||||||
u32 did_wake = 0;
|
u32 did_wake = 0;
|
||||||
|
|
||||||
bool did_unblock_some = unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void* data, bool& stop_iterating) {
|
bool did_unblock_some = unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void*, bool& stop_iterating) {
|
||||||
VERIFY(data);
|
|
||||||
VERIFY(b.blocker_type() == Thread::Blocker::Type::Queue);
|
VERIFY(b.blocker_type() == Thread::Blocker::Type::Queue);
|
||||||
auto& blocker = static_cast<Thread::WaitQueueBlocker&>(b);
|
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);
|
VERIFY(did_wake < wake_count);
|
||||||
if (blocker.unblock()) {
|
if (blocker.unblock()) {
|
||||||
if (++did_wake >= wake_count)
|
if (++did_wake >= wake_count)
|
||||||
|
@ -79,12 +76,11 @@ u32 WaitQueue::wake_all()
|
||||||
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: wake_all", this);
|
dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: wake_all", this);
|
||||||
u32 did_wake = 0;
|
u32 did_wake = 0;
|
||||||
|
|
||||||
bool did_unblock_any = unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void* data, bool&) {
|
bool did_unblock_any = unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void*, bool&) {
|
||||||
VERIFY(data);
|
|
||||||
VERIFY(b.blocker_type() == Thread::Blocker::Type::Queue);
|
VERIFY(b.blocker_type() == Thread::Blocker::Type::Queue);
|
||||||
auto& blocker = static_cast<Thread::WaitQueueBlocker&>(b);
|
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()) {
|
if (blocker.unblock()) {
|
||||||
did_wake++;
|
did_wake++;
|
||||||
|
|
|
@ -31,7 +31,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool should_add_blocker(Thread::Blocker& b, void* data) override;
|
virtual bool should_add_blocker(Thread::Blocker& b, void*) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_wake_requested { false };
|
bool m_wake_requested { false };
|
||||||
|
|
Loading…
Reference in a new issue