- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskDispatch.hpp
More file actions
Latest commit
38 lines (29 loc) · 819 Bytes
/
Copy pathTaskDispatch.hpp
File metadata and controls
38 lines (29 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// https://bitbucket.org/wolfpld/etcpak
// Bartosz Taudul <wolf.pld@gmail.com>
#ifndef __DARKRL__TASKDISPATCH_HPP__
#define__DARKRL__TASKDISPATCH_HPP__
#include<atomic>
#include<condition_variable>
#include<functional>
#include<mutex>
#include<thread>
#include<queue>
#include<vector>
classTaskDispatch
{
public:
TaskDispatch(size_t workers);
~TaskDispatch();
staticvoidQueue(const std::function<void(void)>& f);
staticvoidQueue(std::function<void(void)>&& f);
staticvoidSync();
private:
voidWorker();
std::queue<std::function<void(void)>> m_queue;
std::mutex m_queueLock;
std::condition_variable m_cvWork, m_cvJobs;
std::atomic<bool> m_exit;
size_t m_jobs;
std::vector<std::thread> m_workers;
};
#endif