blob: 8977ee387db0470afdf7b6426719754882c914e6 (
plain) (
tree)
|
|
/* Copyright (c) 2020 Johannes Stoelp */
#include "executor.h"
#include "arch/x86_64/asm.h"
namespace nMatcha {
void Executor::spawn(std::unique_ptr<Thread> t) {
mThreads.push_front(std::move(t));
mThreads.front()->mExecutor = this;
}
void Executor::run() {
while (!mThreads.empty()) {
for (const std::unique_ptr<Thread>& t : mThreads) {
if (!t->isFinished()) {
yield_to(t.get());
}
}
mThreads.remove_if([](const std::unique_ptr<Thread>& t) { return t->isFinished(); });
}
}
void Executor::yield_to(const Thread* t) const { ::yield(t->mStackPtr, &mStackPtr); }
} // namespace nMatcha
|