Files
RayTracer/src/ThreadPool.h
T

26 lines
556 B
C++
Raw Normal View History

2025-01-24 18:21:34 +01:00
#pragma once
#include <condition_variable>
#include <functional>
#include <list>
#include <thread>
2025-01-24 21:54:38 +01:00
struct Batch
{
std::list<std::function<void()>> jobs;
};
2025-01-24 18:21:34 +01:00
class ThreadPool
{
public:
ThreadPool(uint32_t numWorkers = std::thread::hardware_concurrency());
~ThreadPool();
2025-01-24 21:54:38 +01:00
void runBatch(Batch&& batch);
2025-01-24 18:21:34 +01:00
private:
std::atomic_bool running = true;
void work();
std::mutex queueLock;
std::condition_variable queueCV;
std::condition_variable completedCV;
2025-01-24 21:54:38 +01:00
std::list<Batch> taskQueue;
2025-01-24 18:21:34 +01:00
std::vector<std::thread> workers;
};