From 40335c667870e72deb739b81ffbf8d23902ebe71 Mon Sep 17 00:00:00 2001 From: johannst Date: Mon, 5 Oct 2020 17:57:26 +0200 Subject: add support for function objects --- lib/thread.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib/thread.h') diff --git a/lib/thread.h b/lib/thread.h index d983734..3304892 100644 --- a/lib/thread.h +++ b/lib/thread.h @@ -2,6 +2,9 @@ #pragma once +#include +#include + namespace nMatcha { struct Executor; @@ -26,4 +29,24 @@ namespace nMatcha { friend struct Executor; const Executor* mExecutor; }; + + struct Yielder { + virtual void yield() = 0; + }; + + struct FnThread : public Thread, public Yielder { + using UserFn = std::function; + static std::unique_ptr make(UserFn f); + + private: + virtual void threadFn() override; + virtual void yield() override; + + UserFn mUserFn; + + enum class CreatorToken {}; + + public: + FnThread(CreatorToken, UserFn f) : mUserFn(f) {} + }; } // namespace nMatcha -- cgit v1.2.3