00001
#ifndef PtThreadPool_H
00002
#define PtThreadPool_H
00003
00004
#include "Exceptions.h"
00005
#include "ClosableFifoQueue.h"
00006
#include "Runnable.h"
00007
#include "PtMutex.h"
00008
#include <pthread.h>
00009
#include <queue>
00010
#include <set>
00011
#include <string>
00012
00013 BOREALIS_NAMESPACE_BEGIN;
00014
00015 class PtThreadPool
00016 {
00017
public:
00018
00019
00020
00021
00022
00023
PtThreadPool(
int minThreads,
00024
int maxThreads,
00025
ClosableFifoQueue<Runnable*> & executedRunnables)
00026
throw (std::exception);
00027
00028
virtual ~PtThreadPool();
00029
00030
00031
00032
00033
00034
00035
00036
void schedule(
Runnable * pRunnable)
00037
throw (std::exception);
00038
00039
00040
00041
00042
00043
void quiesce()
00044
throw (std::exception);
00045
00046
private:
00047
static void *threadFunc(
void *pPool);
00048
00049
00050
00051
void createServerThread()
00052
throw (std::exception);
00053
00054
00055
void serverThreadMethod();
00056
00057
ClosableFifoQueue<Runnable*> _scheduledRunnables;
00058
ClosableFifoQueue<Runnable*> & _executedRunnables;
00059
00060
int _minThreads;
00061
int _maxThreads;
00062
int _numCurrentThreads;
00063
int _numPendingRunnables;
00064
00065
00066
PtMutex _mtx;
00067
00068 set<pthread_t> _threads;
00069
00070
00071
00072
BinarySem _allThreadsQuiescing;
00073 };
00074
00075 BOREALIS_NAMESPACE_END;
00076
00077
#endif