2012-06-17 20:35:56 +02:00
|
|
|
#ifndef THREADPOOL_H
|
|
|
|
#define THREADPOOL_H
|
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
|
|
|
class I2_BASE_API ThreadPool : public Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef shared_ptr<ThreadPool> Ptr;
|
|
|
|
typedef weak_ptr<ThreadPool> WeakPtr;
|
|
|
|
|
|
|
|
typedef function<void()> Task;
|
|
|
|
|
2012-06-19 09:38:20 +02:00
|
|
|
ThreadPool(long numThreads = 16);
|
2012-06-17 20:35:56 +02:00
|
|
|
~ThreadPool(void);
|
|
|
|
|
|
|
|
static ThreadPool::Ptr GetDefaultPool(void);
|
|
|
|
|
2012-06-18 17:23:48 +02:00
|
|
|
void EnqueueTasks(const vector<Task>& tasks);
|
2012-06-17 20:35:56 +02:00
|
|
|
void EnqueueTask(Task task);
|
2012-06-18 06:44:26 +02:00
|
|
|
void WaitForTasks(void);
|
2012-06-17 20:35:56 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
mutex m_Lock;
|
|
|
|
condition_variable m_CV;
|
|
|
|
|
2012-06-18 06:29:48 +02:00
|
|
|
deque<Task> m_Tasks;
|
2012-06-17 20:35:56 +02:00
|
|
|
|
|
|
|
thread_group m_Threads;
|
|
|
|
bool m_Alive;
|
|
|
|
|
|
|
|
void WorkerThreadProc(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-18 01:29:02 +02:00
|
|
|
#endif /* THREADPOOL_H */
|