mirror of
https://github.com/donnaskiez/ac.git
synced 2024-11-21 22:24:08 +01:00
85c6fd6665
* csq stuff * oh yea * bugfix * epicc * some formating n dat * bug fix * class changes * e * fix up some of the io stuff * fix io PLEASEEE * fff
30 lines
No EOL
707 B
C++
30 lines
No EOL
707 B
C++
#pragma once
|
|
|
|
#include <functional>
|
|
#include <mutex>
|
|
#include <queue>
|
|
#include <vector>
|
|
|
|
namespace dispatcher {
|
|
/*
|
|
* This ThreadPool class is a simple threadpool implementation that will allow
|
|
* us to delegate jobs to a set number of threads without the constant need to
|
|
* close and open new threads.
|
|
*/
|
|
class thread_pool {
|
|
int thread_count;
|
|
bool should_terminate;
|
|
std::mutex queue_mutex;
|
|
std::condition_variable mutex_condition;
|
|
std::vector<std::thread> threads;
|
|
std::queue<std::function<void()>> jobs;
|
|
|
|
void wait_for_task();
|
|
|
|
public:
|
|
thread_pool(int thread_count);
|
|
void queue_job(const std::function<void()> &job);
|
|
void terminate();
|
|
bool busy_wait();
|
|
};
|
|
} // namespace dispatcher
|