diff options
author | johannst <johannes.stoelp@gmail.com> | 2020-09-28 00:23:30 +0200 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2020-09-28 00:23:30 +0200 |
commit | 38d7af6768871a5d285e776bbcfe18b6e7440cfb (patch) | |
tree | 7af3c627261085bb02fa3ff0f3c0d2f1993ab95c /lib | |
parent | e948a05981a9136b25f5723040d8060a6a3bc328 (diff) | |
download | matcha-threads-38d7af6768871a5d285e776bbcfe18b6e7440cfb.tar.gz matcha-threads-38d7af6768871a5d285e776bbcfe18b6e7440cfb.zip |
replace vector with fwd list
Diffstat (limited to 'lib')
-rw-r--r-- | lib/executor.cc | 15 | ||||
-rw-r--r-- | lib/executor.h | 4 |
2 files changed, 11 insertions, 8 deletions
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<Thread> 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<Thread>& t : mThreads) { - if (t->isFinished()) { - continue; + while (!mThreads.empty()) { + for (const std::unique_ptr<Thread>& t : mThreads) { + if (!t->isFinished()) { + yield_to(t.get()); + } } - yield_to(t.get()); + + mThreads.remove_if([](const std::unique_ptr<Thread>& 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 <forward_list> #include <memory> -#include <vector> namespace nMatcha { struct Executor { @@ -20,7 +20,7 @@ namespace nMatcha { private: void* mStackPtr; - std::vector<std::unique_ptr<Thread>> mThreads; + std::forward_list<std::unique_ptr<Thread>> mThreads; void yield_to(const Thread* t) const; }; |