From d89c25701381b393839ff38f93f198c4105b2c21 Mon Sep 17 00:00:00 2001 From: johannst Date: Fri, 18 Sep 2020 01:36:00 +0200 Subject: move yielding into Thread base class + make user fn a pure virtual fn and require user to derive from Thread --- lib/matcha.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/matcha.cc') diff --git a/lib/matcha.cc b/lib/matcha.cc index 3f7cd7b..561a08f 100644 --- a/lib/matcha.cc +++ b/lib/matcha.cc @@ -14,7 +14,7 @@ long get_pagesize() { return sysconf(_SC_PAGESIZE); } -Thread::Thread(void (*fn)()) : mUserFn(fn) { +Thread::Thread() { const long PAGE_SIZE = get_pagesize(); const long STACK_SIZE = 8 * PAGE_SIZE; @@ -53,16 +53,16 @@ void Thread::entry(void* obj) { Thread* t = static_cast(obj); puts("thread entry"); - t->mUserFn(); + t->threadFn(); puts("thread done"); } void* gOriginalStack; -void yield_to(const Thread& t) { - yield(t.mStackPtr, &gOriginalStack); +void Thread::yield() { + ::yield(gOriginalStack, &mStackPtr); } -void yield_from(Thread& t) { - yield(gOriginalStack, &t.mStackPtr); +void Thread::yield_to() const { + ::yield(mStackPtr, &gOriginalStack); } -- cgit v1.2.3