Move threading utils from native to Common

This commit is contained in:
Henrik Rydgård committed 2020-10-01 09:27:25 +02:00
1 parent ef08c0237f
commit 15382d5f94
61 files changed
+105 -138

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
#include "Common/Thread/Executor.h"
#include <functional>
#include <thread>
namespace threading {
void SameThreadExecutor::Run(std::function<void()> func) {
func();
}
void NewThreadExecutor::Run(std::function<void()> func) {
threads_.push_back(std::thread(func));
}
NewThreadExecutor::~NewThreadExecutor() {
// If Run was ever called...
for (auto &thread : threads_)
thread.join();
threads_.clear();
}
} // namespace threading