From 38d7af6768871a5d285e776bbcfe18b6e7440cfb Mon Sep 17 00:00:00 2001 From: johannst Date: Mon, 28 Sep 2020 00:23:30 +0200 Subject: replace vector with fwd list --- lib/executor.cc | 15 +++++++++------ lib/executor.h | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/executor.cc b/lib/executor.cc index af49f0e..8977ee3 100644 --- a/lib/executor.cc +++ b/lib/executor.cc @@ -6,16 +6,19 @@ namespace nMatcha { void Executor::spawn(std::unique_ptr t) { - mThreads.push_back(std::move(t)); - mThreads.back()->mExecutor = this; + mThreads.push_front(std::move(t)); + mThreads.front()->mExecutor = this; } void Executor::run() { - for (const std::unique_ptr& t : mThreads) { - if (t->isFinished()) { - continue; + while (!mThreads.empty()) { + for (const std::unique_ptr& t : mThreads) { + if (!t->isFinished()) { + yield_to(t.get()); + } } - yield_to(t.get()); + + mThreads.remove_if([](const std::unique_ptr& t) { return t->isFinished(); }); } } diff --git a/lib/executor.h b/lib/executor.h index 5d2e5b6..67493d4 100644 --- a/lib/executor.h +++ b/lib/executor.h @@ -4,8 +4,8 @@ #include "thread.h" +#include #include -#include namespace nMatcha { struct Executor { @@ -20,7 +20,7 @@ namespace nMatcha { private: void* mStackPtr; - std::vector> mThreads; + std::forward_list> mThreads; void yield_to(const Thread* t) const; }; -- cgit v1.2.3