erebus

diff liberebus/src/threadpool.h @ 24:4336acf8389d

implemented thread pool. not using it yet.
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 30 May 2014 06:56:44 +0300
parents
children c8a6fb04fefa
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/liberebus/src/threadpool.h	Fri May 30 06:56:44 2014 +0300
     1.3 @@ -0,0 +1,30 @@
     1.4 +#ifndef THREAD_POOL_H_
     1.5 +#define THREAD_POOL_H_
     1.6 +
     1.7 +#include <list>
     1.8 +#include <functional>
     1.9 +#include <thread>
    1.10 +#include <mutex>
    1.11 +#include <condition_variable>
    1.12 +
    1.13 +class ThreadPool {
    1.14 +private:
    1.15 +	int num_threads;
    1.16 +	std::thread *thread;	// array of threads
    1.17 +
    1.18 +	std::list<std::function<void ()>> workq;
    1.19 +	std::mutex workq_mutex;
    1.20 +	std::condition_variable condvar;
    1.21 +
    1.22 +	bool quit;
    1.23 +
    1.24 +	void thread_func();
    1.25 +
    1.26 +public:
    1.27 +	ThreadPool(int num_threads = -1);
    1.28 +	~ThreadPool();
    1.29 +
    1.30 +	void add_work(std::function<void ()> func);
    1.31 +};
    1.32 +
    1.33 +#endif	// THREAD_POOL_H_
    1.34 \ No newline at end of file