VWeb/Includes/ThreadPool.h

27 lines
550 B
C
Raw Normal View History

#pragma once
#include "Queue.h"
#include "Types.h"
namespace VWeb {
struct WorkerJob {
virtual ~WorkerJob() = default;
virtual void Execute() = 0;
};
class ThreadPool {
public:
explicit ThreadPool(std::string name);
void SetThreadCount(int);
void Dispatch(const Ref<WorkerJob> &);
void Create();
void Stop();
void Execute();
protected:
std::string m_Name;
int m_ThreadCount{1};
bool m_IsCreated{false};
std::vector<std::thread> m_Threads{};
SafeQueue<Ref<WorkerJob>> m_Queue;
bool m_IsDone{false};
};
} // namespace VWeb