build_system_2022/thread_pool.hpp

30 lines
563 B
C++
Raw Normal View History

2022-08-04 01:22:09 +03:00
#pragma once
#include <cstddef>
#include <functional>
#include <thread>
#include <vector>
#include "dependency_manager.hpp"
#include "task_queue.hpp"
namespace build_system {
class ThreadPool {
public:
explicit ThreadPool(size_t num_threads) : num_threads_(num_threads) {}
void addTarget(Task&& task, size_t id, const std::vector<size_t>& dependences);
void start();
void wait();
private:
size_t num_threads_;
std::vector<std::thread> threads_;
TaskQueue task_queue_;
DependencyManager dependency_manager_;
};
}; // namespace build_system