TDME2  1.9.200
ServerWorkerThreadPool.cpp
Go to the documentation of this file.
2 
3 #include <memory>
4 #include <vector>
5 
6 #include <tdme/tdme.h>
11 
12 using std::make_unique;
13 using std::vector;
14 using std::unique_ptr;
15 
17 
21 
22 ServerWorkerThreadPool::ServerWorkerThreadPool(const unsigned int workerCount, const unsigned int maxElements, Barrier* startUpBarrier) :
23  Queue<ServerRequest>(maxElements),
24  workerCount(workerCount),
25  startUpBarrier(startUpBarrier) {
26  //
27 }
28 
30 }
31 
33  worker.resize(workerCount);
34  for(auto i = 0; i < workerCount; i++) {
35  worker[i] = make_unique<ServerWorkerThread>(i, this, startUpBarrier);
36  worker[i]->start();
37  }
38 }
39 
41  // stop queue
43 
44  // stop worker
45  for(auto i = 0; i < worker.size(); i++) {
46  // wait until worker has finished
47  worker[i]->join();
48  }
49  //
50  worker.clear();
51 }
Simple server worker thread pool class.
vector< unique_ptr< ServerWorkerThread > > worker
Barrier implementation.
Definition: Barrier.h:21
Consumer/producer queue.
Definition: Queue.h:26