From b30081b49ac91953073fec0420652cb605a85388 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 22 Aug 2021 17:38:16 +0200 Subject: [PATCH] Kernel: Rename BlockerSet::unblock() to something more accurate Namely, unblock_all_blockers_whose_conditions_are_met(). The old name made it sound like things were getting unblocked no matter what, but that's not actually the case. What this actually does is iterate through the set of blockers, unblocking those whose conditions are met. So give it a (very) verbose name that errs on the side of descriptiveness. --- Kernel/FileSystem/File.h | 6 +++--- Kernel/FileSystem/FileDescription.h | 2 +- Kernel/FileSystem/Plan9FileSystem.cpp | 4 ++-- Kernel/FutexQueue.cpp | 6 +++--- Kernel/Net/Routing.cpp | 2 +- Kernel/Thread.h | 20 ++++++++++---------- Kernel/ThreadBlockers.cpp | 4 ++-- Kernel/WaitQueue.cpp | 6 +++--- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Kernel/FileSystem/File.h b/Kernel/FileSystem/File.h index dc5977ee70e..276a3837472 100644 --- a/Kernel/FileSystem/File.h +++ b/Kernel/FileSystem/File.h @@ -32,10 +32,10 @@ public: return !blocker.unblock(true, data); } - void unblock() + void unblock_all_blockers_whose_conditions_are_met() { SpinlockLocker lock(m_lock); - do_unblock([&](auto& b, void* data, bool&) { + BlockerSet::unblock_all_blockers_whose_conditions_are_met_locked([&](auto& b, void* data, bool&) { VERIFY(b.blocker_type() == Thread::Blocker::Type::File); auto& blocker = static_cast(b); return blocker.unblock(false, data); @@ -138,7 +138,7 @@ private: ALWAYS_INLINE void do_evaluate_block_conditions() { VERIFY(!Processor::current_in_irq()); - blocker_set().unblock(); + blocker_set().unblock_all_blockers_whose_conditions_are_met(); } FileBlockerSet m_blocker_set; diff --git a/Kernel/FileSystem/FileDescription.h b/Kernel/FileSystem/FileDescription.h index d5f39924879..05bd10e4c44 100644 --- a/Kernel/FileSystem/FileDescription.h +++ b/Kernel/FileSystem/FileDescription.h @@ -138,7 +138,7 @@ private: void evaluate_block_conditions() { - blocker_set().unblock(); + blocker_set().unblock_all_blockers_whose_conditions_are_met(); } RefPtr m_custody; diff --git a/Kernel/FileSystem/Plan9FileSystem.cpp b/Kernel/FileSystem/Plan9FileSystem.cpp index 6861274a551..7bedfd59975 100644 --- a/Kernel/FileSystem/Plan9FileSystem.cpp +++ b/Kernel/FileSystem/Plan9FileSystem.cpp @@ -451,7 +451,7 @@ bool Plan9FS::Plan9FSBlockerSet::should_add_blocker(Thread::Blocker& b, void*) void Plan9FS::Plan9FSBlockerSet::unblock_completed(u16 tag) { - unblock([&](Thread::Blocker& b, void*, bool&) { + unblock_all_blockers_whose_conditions_are_met([&](Thread::Blocker& b, void*, bool&) { VERIFY(b.blocker_type() == Thread::Blocker::Type::Plan9FS); auto& blocker = static_cast(b); return blocker.unblock(tag); @@ -460,7 +460,7 @@ void Plan9FS::Plan9FSBlockerSet::unblock_completed(u16 tag) void Plan9FS::Plan9FSBlockerSet::unblock_all() { - unblock([&](Thread::Blocker& b, void*, bool&) { + unblock_all_blockers_whose_conditions_are_met([&](Thread::Blocker& b, void*, bool&) { VERIFY(b.blocker_type() == Thread::Blocker::Type::Plan9FS); auto& blocker = static_cast(b); return blocker.unblock(); diff --git a/Kernel/FutexQueue.cpp b/Kernel/FutexQueue.cpp index 2d747ea1dec..06ecf929497 100644 --- a/Kernel/FutexQueue.cpp +++ b/Kernel/FutexQueue.cpp @@ -44,7 +44,7 @@ u32 FutexQueue::wake_n_requeue(u32 wake_count, const Function& ge dbgln_if(FUTEXQUEUE_DEBUG, "FutexQueue @ {}: wake_n_requeue({}, {})", this, wake_count, requeue_count); u32 did_wake = 0, did_requeue = 0; - do_unblock([&](Thread::Blocker& b, void* data, bool& stop_iterating) { + unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void* data, bool& stop_iterating) { VERIFY(data); VERIFY(b.blocker_type() == Thread::Blocker::Type::Futex); auto& blocker = static_cast(b); @@ -103,7 +103,7 @@ u32 FutexQueue::wake_n(u32 wake_count, const Optional& bitset, bool& is_emp SpinlockLocker lock(m_lock); dbgln_if(FUTEXQUEUE_DEBUG, "FutexQueue @ {}: wake_n({})", this, wake_count); u32 did_wake = 0; - do_unblock([&](Thread::Blocker& b, void* data, bool& stop_iterating) { + unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void* data, bool& stop_iterating) { VERIFY(data); VERIFY(b.blocker_type() == Thread::Blocker::Type::Futex); auto& blocker = static_cast(b); @@ -126,7 +126,7 @@ u32 FutexQueue::wake_all(bool& is_empty) SpinlockLocker lock(m_lock); dbgln_if(FUTEXQUEUE_DEBUG, "FutexQueue @ {}: wake_all", this); u32 did_wake = 0; - do_unblock([&](Thread::Blocker& b, void* data, bool&) { + unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void* data, bool&) { VERIFY(data); VERIFY(b.blocker_type() == Thread::Blocker::Type::Futex); auto& blocker = static_cast(b); diff --git a/Kernel/Net/Routing.cpp b/Kernel/Net/Routing.cpp index 2b4d6209113..89223cdcca1 100644 --- a/Kernel/Net/Routing.cpp +++ b/Kernel/Net/Routing.cpp @@ -59,7 +59,7 @@ class ARPTableBlockerSet final : public Thread::BlockerSet { public: void unblock(const IPv4Address& ip_addr, const MACAddress& addr) { - BlockerSet::unblock([&](auto& b, void*, bool&) { + BlockerSet::unblock_all_blockers_whose_conditions_are_met([&](auto& b, void*, bool&) { VERIFY(b.blocker_type() == Thread::Blocker::Type::Routing); auto& blocker = static_cast(b); return blocker.unblock(false, ip_addr, addr); diff --git a/Kernel/Thread.h b/Kernel/Thread.h index 8bb7ed1d6e6..4a954c03086 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -427,30 +427,30 @@ public: } protected: - template - bool unblock(UnblockOne unblock_one) + template + bool unblock_all_blockers_whose_conditions_are_met(Callback try_to_unblock_one) { SpinlockLocker lock(m_lock); - return do_unblock(unblock_one); + return unblock_all_blockers_whose_conditions_are_met_locked(try_to_unblock_one); } - template - bool do_unblock(UnblockOne unblock_one) + template + bool unblock_all_blockers_whose_conditions_are_met_locked(Callback try_to_unblock_one) { VERIFY(m_lock.is_locked()); bool stop_iterating = false; - bool did_unblock = false; + bool did_unblock_any = false; for (size_t i = 0; i < m_blockers.size() && !stop_iterating;) { auto& info = m_blockers[i]; - if (unblock_one(*info.blocker, info.data, stop_iterating)) { + if (bool did_unblock = try_to_unblock_one(*info.blocker, info.data, stop_iterating)) { m_blockers.remove(i); - did_unblock = true; + did_unblock_any = true; continue; } i++; } - return did_unblock; + return did_unblock_any; } bool is_empty_locked() const @@ -1267,7 +1267,7 @@ private: private: void do_unblock_joiner() { - do_unblock([&](Blocker& b, void*, bool&) { + unblock_all_blockers_whose_conditions_are_met_locked([&](Blocker& b, void*, bool&) { VERIFY(b.blocker_type() == Blocker::Type::Join); auto& blocker = static_cast(b); return blocker.unblock(exit_value(), false); diff --git a/Kernel/ThreadBlockers.cpp b/Kernel/ThreadBlockers.cpp index c67e30d4010..fd2ac4a06f5 100644 --- a/Kernel/ThreadBlockers.cpp +++ b/Kernel/ThreadBlockers.cpp @@ -478,7 +478,7 @@ void Thread::WaitBlockerSet::disowned_by_waiter(Process& process) for (size_t i = 0; i < m_processes.size();) { auto& info = m_processes[i]; if (info.process == &process) { - do_unblock([&](Blocker& b, void*, bool&) { + unblock_all_blockers_whose_conditions_are_met_locked([&](Blocker& b, void*, bool&) { VERIFY(b.blocker_type() == Blocker::Type::Wait); auto& blocker = static_cast(b); bool did_unblock = blocker.unblock(info.process, WaitBlocker::UnblockFlags::Disowned, 0, false); @@ -515,7 +515,7 @@ bool Thread::WaitBlockerSet::unblock(Process& process, WaitBlocker::UnblockFlags } } - do_unblock([&](Blocker& b, void*, bool&) { + unblock_all_blockers_whose_conditions_are_met_locked([&](Blocker& b, void*, bool&) { VERIFY(b.blocker_type() == Blocker::Type::Wait); auto& blocker = static_cast(b); if (was_waited_already && blocker.is_wait()) diff --git a/Kernel/WaitQueue.cpp b/Kernel/WaitQueue.cpp index 6d0ae360e13..65c74b3bdbd 100644 --- a/Kernel/WaitQueue.cpp +++ b/Kernel/WaitQueue.cpp @@ -29,7 +29,7 @@ u32 WaitQueue::wake_one() u32 did_wake = 0; SpinlockLocker lock(m_lock); dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: wake_one", this); - bool did_unblock_one = do_unblock([&](Thread::Blocker& b, void* data, bool& stop_iterating) { + bool did_unblock_one = unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void* data, bool& stop_iterating) { VERIFY(data); VERIFY(b.blocker_type() == Thread::Blocker::Type::Queue); auto& blocker = static_cast(b); @@ -54,7 +54,7 @@ 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 = do_unblock([&](Thread::Blocker& b, void* data, bool& stop_iterating) { + bool did_unblock_some = unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void* data, bool& stop_iterating) { VERIFY(data); VERIFY(b.blocker_type() == Thread::Blocker::Type::Queue); auto& blocker = static_cast(b); @@ -79,7 +79,7 @@ u32 WaitQueue::wake_all() dbgln_if(WAITQUEUE_DEBUG, "WaitQueue @ {}: wake_all", this); u32 did_wake = 0; - bool did_unblock_any = do_unblock([&](Thread::Blocker& b, void* data, bool&) { + bool did_unblock_any = unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void* data, bool&) { VERIFY(data); VERIFY(b.blocker_type() == Thread::Blocker::Type::Queue); auto& blocker = static_cast(b);