mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
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.
This commit is contained in:
parent
6c16bedd69
commit
b30081b49a
|
@ -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<Thread::FileBlocker&>(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;
|
||||
|
|
|
@ -138,7 +138,7 @@ private:
|
|||
|
||||
void evaluate_block_conditions()
|
||||
{
|
||||
blocker_set().unblock();
|
||||
blocker_set().unblock_all_blockers_whose_conditions_are_met();
|
||||
}
|
||||
|
||||
RefPtr<Custody> m_custody;
|
||||
|
|
|
@ -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<Blocker&>(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<Blocker&>(b);
|
||||
return blocker.unblock();
|
||||
|
|
|
@ -44,7 +44,7 @@ u32 FutexQueue::wake_n_requeue(u32 wake_count, const Function<FutexQueue*()>& 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<Thread::FutexBlocker&>(b);
|
||||
|
@ -103,7 +103,7 @@ u32 FutexQueue::wake_n(u32 wake_count, const Optional<u32>& 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<Thread::FutexBlocker&>(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<Thread::FutexBlocker&>(b);
|
||||
|
|
|
@ -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<ARPTableBlocker&>(b);
|
||||
return blocker.unblock(false, ip_addr, addr);
|
||||
|
|
|
@ -427,30 +427,30 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
template<typename UnblockOne>
|
||||
bool unblock(UnblockOne unblock_one)
|
||||
template<typename Callback>
|
||||
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<typename UnblockOne>
|
||||
bool do_unblock(UnblockOne unblock_one)
|
||||
template<typename Callback>
|
||||
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<JoinBlocker&>(b);
|
||||
return blocker.unblock(exit_value(), false);
|
||||
|
|
|
@ -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<WaitBlocker&>(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<WaitBlocker&>(b);
|
||||
if (was_waited_already && blocker.is_wait())
|
||||
|
|
|
@ -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<Thread::QueueBlocker&>(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<Thread::QueueBlocker&>(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<Thread::QueueBlocker&>(b);
|
||||
|
|
Loading…
Reference in a new issue