mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +00:00
Thread: More composition in for_each :)
This commit is contained in:
parent
d092855c72
commit
80a6df9022
Notes:
sideshowbarker
2024-07-19 13:08:43 +09:00
Author: https://github.com/rburchell Commit: https://github.com/SerenityOS/serenity/commit/80a6df90220 Pull-request: https://github.com/SerenityOS/serenity/pull/343 Reviewed-by: https://github.com/awesomekling
1 changed files with 8 additions and 26 deletions
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue