DIE Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
workerpool.h
Go to the documentation of this file.
1
11
12
#ifndef WORKERPOOL_H
13
#define WORKERPOOL_H
14
15
#include <vector>
16
#include <thread>
17
#include <functional>
18
#include <mutex>
19
#include <condition_variable>
20
21
/*****************************************************************************/
25
class
WorkerPool
26
{
27
public
:
28
static
constexpr
unsigned
WorkersMax
= 8;
29
30
WorkerPool
();
31
~WorkerPool
();
32
34
void
enqueue
(std::function<
void
()> job);
35
37
void
waitAll
();
38
40
int
workerCount
()
const
{
return
activeWorkers;}
41
42
private
:
43
std::vector<std::thread> workers;
44
std::vector<std::function<void()>> jobs;
45
46
std::mutex queueMutex;
47
48
std::condition_variable jobCV;
49
std::condition_variable waitCV;
50
51
bool
stop;
52
int
jobsPrepared;
53
int
jobsUnfinished;
54
int
activeWorkers;
55
};
56
57
#endif
// WORKERPOOL_H
WorkerPool::enqueue
void enqueue(std::function< void()> job)
Add a job to the pool (jobs may run in any order).
Definition
workerpool.cpp:62
WorkerPool::WorkerPool
WorkerPool()
Definition
workerpool.cpp:17
WorkerPool::WorkersMax
static constexpr unsigned WorkersMax
Definition
workerpool.h:28
WorkerPool::workerCount
int workerCount() const
Number of worker threads in the pool.
Definition
workerpool.h:40
WorkerPool::waitAll
void waitAll()
Block until all enqueued jobs have completed.
Definition
workerpool.cpp:73
WorkerPool::~WorkerPool
~WorkerPool()
Definition
workerpool.cpp:51
common
engine
workerpool.h
Generated by
1.17.0