Permalink
Browse files

thread: Add a simple thread executor.

  • Loading branch information...
unknownbrackets committed Apr 13, 2018
1 parent 403632b commit 042256337a1e8be0d539b12217edfbe4233f7e7a
Showing with 15 additions and 5 deletions.
  1. +6 −1 ext/native/thread/executor.cpp
  2. +9 −4 ext/native/thread/executor.h
@@ -1,11 +1,16 @@
#include "thread/executor.h"
#include <functional>
#include <thread>
namespace threading {
void SameThreadExecutor::Run(std::function<void()> func) {
func();
func();
}
void NewThreadExecutor::Run(std::function<void()> func) {
std::thread(func).detach();
}
} // namespace threading
@@ -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<void()> func) = 0;
public:
virtual void Run(std::function<void()> func) = 0;
};
class SameThreadExecutor : public Executor {
public:
virtual void Run(std::function<void()> func);
public:
void Run(std::function<void()> func) override;
};
class NewThreadExecutor : public Executor {
public:
void Run(std::function<void()> func) override;
};
} // namespace threading

0 comments on commit 0422563

Please sign in to comment.