2020-10-01 09:27:25 +02:00
|
|
|
#include "Common/Thread/Executor.h"
|
2016-10-12 11:32:24 +02:00
|
|
|
|
|
|
|
#include <functional>
|
2018-04-12 20:30:12 -07:00
|
|
|
#include <thread>
|
2014-12-15 00:00:16 +01:00
|
|
|
|
|
|
|
namespace threading {
|
|
|
|
|
|
|
|
void SameThreadExecutor::Run(std::function<void()> func) {
|
2018-04-12 20:30:12 -07:00
|
|
|
func();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewThreadExecutor::Run(std::function<void()> func) {
|
2020-03-09 18:25:32 -07:00
|
|
|
threads_.push_back(std::thread(func));
|
2020-03-03 23:07:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NewThreadExecutor::~NewThreadExecutor() {
|
|
|
|
// If Run was ever called...
|
2020-03-09 18:25:32 -07:00
|
|
|
for (auto &thread : threads_)
|
|
|
|
thread.join();
|
|
|
|
threads_.clear();
|
2014-12-15 00:00:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace threading
|