-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathTaskDispatch.hpp
More file actions
34 lines (26 loc) · 687 Bytes
/
TaskDispatch.hpp
File metadata and controls
34 lines (26 loc) · 687 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
#ifndef __DARKRL__TASKDISPATCH_HPP__
#define __DARKRL__TASKDISPATCH_HPP__
#include <atomic>
#include <condition_variable>
#include <functional>
#include <mutex>
#include <thread>
#include <vector>
class TaskDispatch
{
public:
TaskDispatch( size_t workers );
~TaskDispatch();
static void Queue( const std::function<void(void)>& f );
static void Queue( std::function<void(void)>&& f );
static void Sync();
private:
void Worker();
std::vector<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