renderd7/source/Tasks.cpp

23 lines
496 B
C++
Raw Normal View History

#include <memory>
2024-02-19 19:20:37 +01:00
#include <renderd7/Tasks.hpp>
#include <thread>
#include <vector>
2024-02-19 19:20:37 +01:00
static std::vector<std::shared_ptr<std::thread>> threads;
2024-02-19 19:20:37 +01:00
int RenderD7::Tasks::Create(std::function<void()> fun) {
auto thrd = std::make_shared<std::thread>(fun);
threads.push_back(thrd);
return threads.size();
2024-02-19 19:20:37 +01:00
}
void RenderD7::Tasks::DestroyAll() {
for (auto& it : threads) {
if (it && it->joinable()) {
it->join();
}
2024-02-19 19:20:37 +01:00
}
// Delete Pointers
threads.clear();
}