aboutsummaryrefslogtreecommitdiff
path: root/lib/executor.cc
blob: fb79b49614877f78b2e4d2952a697c113d8ea136 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* 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_back(std::move(t));
        mThreads.back()->mExecutor = this;
    }

    void Executor::run() {
        for (const std::unique_ptr<Thread>& t : mThreads) {
            yield_to(t.get());
        }
    }

    void Executor::yield_to(const Thread* t) const { ::yield(t->mStackPtr, &mStackPtr); }
}  // namespace nMatcha