From 80a6df90220981e64e0ca192908163d3a263ffc6 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Fri, 19 Jul 2019 12:22:46 +0200 Subject: [PATCH] Thread: More composition in for_each :) --- Kernel/Thread.h | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/Kernel/Thread.h b/Kernel/Thread.h index c5ac7eb032b..bd7bbc1081d 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -316,38 +316,20 @@ template inline IterationDecision Thread::for_each_in_state(State state, Callback callback) { ASSERT_INTERRUPTS_DISABLED(); - for (auto* thread = thread_list_for_state(state)->head(); thread;) { - auto* next_thread = thread->next(); - if (thread->state() == state) { - if (callback(*thread) == IterationDecision::Break) - return IterationDecision::Break; - } - thread = next_thread; - } - - return IterationDecision::Continue; + if (is_runnable_state(state)) + return for_each_runnable(callback); + return for_each_nonrunnable(callback); } template inline IterationDecision Thread::for_each_living(Callback callback) { ASSERT_INTERRUPTS_DISABLED(); - for (auto* thread = g_runnable_threads->head(); thread;) { - auto* next_thread = thread->next(); - if (thread->state() != Thread::State::Dead && thread->state() != Thread::State::Dying) - if (callback(*thread) == IterationDecision::Break) - return IterationDecision::Break; - thread = next_thread; - } - for (auto* thread = g_nonrunnable_threads->head(); thread;) { - auto* next_thread = thread->next(); - if (thread->state() != Thread::State::Dead && thread->state() != Thread::State::Dying) - if (callback(*thread) == IterationDecision::Break) - return IterationDecision::Break; - thread = next_thread; - } - - return IterationDecision::Continue; + return Thread::for_each([callback](Thread& thread) -> IterationDecision { + if (thread.state() != Thread::State::Dead && thread.state() != Thread::State::Dying) + return callback(thread); + return IterationDecision::Continue; + }); } template