mirror-ac/module/dispatcher/threadpool.h
donnaskiez 85c6fd6665
Rewrite IO handling (#6)
* 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
2024-01-21 18:22:06 +11:00

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