Skip to content

Commit

Permalink
Thread: More composition in for_each :)
Browse files Browse the repository at this point in the history
  • Loading branch information
rburchell authored and awesomekling committed Jul 19, 2019
1 parent d092855 commit 80a6df9
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions Kernel/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,38 +316,20 @@ template<typename Callback>
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<typename Callback>
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<typename Callback>
Expand Down

0 comments on commit 80a6df9

Please sign in to comment.