TDME2
1.9.121
src
tdme
network
udpserver
ServerWorkerThreadPool.cpp
Go to the documentation of this file.
1
#include <
tdme/network/udpserver/ServerWorkerThreadPool.h
>
2
3
#include <
tdme/tdme.h
>
4
#include <
tdme/utilities/Console.h
>
5
6
using
tdme::network::udpserver::ServerWorkerThreadPool
;
7
using
tdme::os::threading::Queue
;
8
using
tdme::utilities::Console
;
9
10
ServerWorkerThreadPool::ServerWorkerThreadPool(
Barrier
* startUpBarrier,
const
unsigned
int
workerCount,
const
unsigned
int
maxElements) :
11
Queue
<
ServerRequest
>(maxElements),
12
13
startUpBarrier(startUpBarrier),
14
workerCount(workerCount),
15
worker(NULL) {
16
//
17
}
18
19
ServerWorkerThreadPool::~ServerWorkerThreadPool
() {
20
}
21
22
void
ServerWorkerThreadPool::start
() {
23
worker
=
new
ServerWorkerThread
*[
workerCount
];
24
for
(
unsigned
int
i = 0; i <
workerCount
; i++) {
25
worker
[i] =
new
ServerWorkerThread
(i,
this
);
26
worker
[i]->
start
();
27
}
28
}
29
30
void
ServerWorkerThreadPool::stop
() {
31
// stop queue
32
Queue<ServerRequest>::stop
();
33
34
// stop worker
35
for
(
unsigned
int
i = 0; i <
workerCount
; i++) {
36
// wait until worker has finished
37
worker
[i]->
join
();
38
// delete worker
39
delete
worker
[i];
40
}
41
delete
[]
worker
;
42
}
Console.h
ServerWorkerThreadPool.h
tdme::network::udpserver::ServerRequest
Server request bean.
Definition:
ServerRequest.h:25
tdme::network::udpserver::ServerWorkerThreadPool
Simple server worker thread pool class.
Definition:
ServerWorkerThreadPool.h:23
tdme::network::udpserver::ServerWorkerThreadPool::~ServerWorkerThreadPool
virtual ~ServerWorkerThreadPool()
Public destructor.
Definition:
ServerWorkerThreadPool.cpp:19
tdme::network::udpserver::ServerWorkerThreadPool::worker
ServerWorkerThread ** worker
Definition:
ServerWorkerThreadPool.h:53
tdme::network::udpserver::ServerWorkerThreadPool::ServerWorkerThread
friend class ServerWorkerThread
Definition:
ServerWorkerThreadPool.h:24
tdme::network::udpserver::ServerWorkerThreadPool::start
void start()
Start worker thread pool.
Definition:
ServerWorkerThreadPool.cpp:22
tdme::network::udpserver::ServerWorkerThreadPool::stop
void stop()
Stop worker thread pool.
Definition:
ServerWorkerThreadPool.cpp:30
tdme::network::udpserver::ServerWorkerThreadPool::workerCount
unsigned int workerCount
Definition:
ServerWorkerThreadPool.h:52
tdme::network::udpserver::ServerWorkerThread
Server worker thread.
Definition:
ServerWorkerThread.h:21
tdme::os::threading::Barrier
Barrier implementation.
Definition:
Barrier.h:21
tdme::os::threading::Queue
Consumer/producer queue.
Definition:
Queue.h:24
tdme::os::threading::Thread::start
void start()
Starts this objects thread.
Definition:
Thread.cpp:65
tdme::os::threading::Thread::join
void join()
Blocks caller thread until this thread has been terminated.
Definition:
Thread.cpp:55
tdme::utilities::Console
Console class.
Definition:
Console.h:26
tdme.h
Generated by
1.9.3