aboutsummaryrefslogtreecommitdiff
path: root/lib/matcha.h
diff options
context:
space:
mode:
authorjohannst <johannes.stoelp@gmail.com>2020-09-22 23:48:09 +0200
committerjohannst <johannes.stoelp@gmail.com>2020-09-22 23:48:09 +0200
commit33f286000db35fe50639c237caa736deea304585 (patch)
treeddb74ebd1f626b200cbb5050545ded484dde4787 /lib/matcha.h
parent488d4c6237c3f713077fe93e2745ba5defde0aa5 (diff)
downloadmatcha-threads-33f286000db35fe50639c237caa736deea304585.tar.gz
matcha-threads-33f286000db35fe50639c237caa736deea304585.zip
split classes into separate files, add arch specific subdir
Diffstat (limited to 'lib/matcha.h')
-rw-r--r--lib/matcha.h50
1 files changed, 0 insertions, 50 deletions
diff --git a/lib/matcha.h b/lib/matcha.h
deleted file mode 100644
index 5843cb7..0000000
--- a/lib/matcha.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* Copyright (c) 2020 Johannes Stoelp */
-
-#include <memory>
-#include <vector>
-
-struct Executor;
-
-struct Thread {
- Thread(const Thread&) = delete;
- Thread& operator=(const Thread&) = delete;
- Thread();
- virtual ~Thread() {}
-
- virtual void threadFn() = 0;
-
- protected:
- void yield();
-
- private:
- static void entry(void* obj);
- void* mStackPtr;
-
- friend struct Executor;
- const Executor* mExecutor;
-};
-
-
-struct Executor {
- Executor(const Executor&) = delete;
- Executor& operator=(const Executor&) = delete;
- Executor() = default;
-
- const void* getStackPtr() const { return mStackPtr; }
-
- void spawn(std::unique_ptr<Thread> t) {
- mThreads.push_back(std::move(t));
- mThreads.back()->mExecutor = this;
- }
- void run() {
- for (const std::unique_ptr<Thread>& t : mThreads) {
- yield_to(t.get());
- }
- }
-
- private:
- void* mStackPtr;
- std::vector<std::unique_ptr<Thread>> mThreads;
-
- void yield_to(const Thread* t) const;
-};