From 042256337a1e8be0d539b12217edfbe4233f7e7a Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 12 Apr 2018 20:30:12 -0700 Subject: [PATCH] thread: Add a simple thread executor. --- ext/native/thread/executor.cpp | 7 ++++++- ext/native/thread/executor.h | 13 +++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ext/native/thread/executor.cpp b/ext/native/thread/executor.cpp index 8c5d6cd097..197f9d7920 100644 --- a/ext/native/thread/executor.cpp +++ b/ext/native/thread/executor.cpp @@ -1,11 +1,16 @@ #include "thread/executor.h" #include +#include namespace threading { void SameThreadExecutor::Run(std::function func) { - func(); + func(); +} + +void NewThreadExecutor::Run(std::function func) { + std::thread(func).detach(); } } // namespace threading diff --git a/ext/native/thread/executor.h b/ext/native/thread/executor.h index 7a5b5286a1..6d6515920c 100644 --- a/ext/native/thread/executor.h +++ b/ext/native/thread/executor.h @@ -6,13 +6,18 @@ namespace threading { // Stuff that can execute other stuff, like threadpools, should inherit from this. class Executor { - public: - virtual void Run(std::function func) = 0; +public: + virtual void Run(std::function func) = 0; }; class SameThreadExecutor : public Executor { - public: - virtual void Run(std::function func); +public: + void Run(std::function func) override; +}; + +class NewThreadExecutor : public Executor { +public: + void Run(std::function func) override; }; } // namespace threading