mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +00:00
Thread: More composition in for_each :)
This commit is contained in:
parent
d092855c72
commit
80a6df9022
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)
|
inline IterationDecision Thread::for_each_in_state(State state, Callback callback)
|
||||||
{
|
{
|
||||||
ASSERT_INTERRUPTS_DISABLED();
|
ASSERT_INTERRUPTS_DISABLED();
|
||||||
for (auto* thread = thread_list_for_state(state)->head(); thread;) {
|
if (is_runnable_state(state))
|
||||||
auto* next_thread = thread->next();
|
return for_each_runnable(callback);
|
||||||
if (thread->state() == state) {
|
return for_each_nonrunnable(callback);
|
||||||
if (callback(*thread) == IterationDecision::Break)
|
|
||||||
return IterationDecision::Break;
|
|
||||||
}
|
|
||||||
thread = next_thread;
|
|
||||||
}
|
|
||||||
|
|
||||||
return IterationDecision::Continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
inline IterationDecision Thread::for_each_living(Callback callback)
|
inline IterationDecision Thread::for_each_living(Callback callback)
|
||||||
{
|
{
|
||||||
ASSERT_INTERRUPTS_DISABLED();
|
ASSERT_INTERRUPTS_DISABLED();
|
||||||
for (auto* thread = g_runnable_threads->head(); thread;) {
|
return Thread::for_each([callback](Thread& thread) -> IterationDecision {
|
||||||
auto* next_thread = thread->next();
|
if (thread.state() != Thread::State::Dead && thread.state() != Thread::State::Dying)
|
||||||
if (thread->state() != Thread::State::Dead && thread->state() != Thread::State::Dying)
|
return callback(thread);
|
||||||
if (callback(*thread) == IterationDecision::Break)
|
return IterationDecision::Continue;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue