erebus

annotate 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
rev   line source
nuclear@24 1 #ifndef THREAD_POOL_H_
nuclear@24 2 #define THREAD_POOL_H_
nuclear@24 3
nuclear@24 4 #include <list>
nuclear@24 5 #include <functional>
nuclear@24 6 #include <thread>
nuclear@24 7 #include <mutex>
nuclear@24 8 #include <condition_variable>
nuclear@24 9
nuclear@24 10 class ThreadPool {
nuclear@24 11 private:
nuclear@24 12 int num_threads;
nuclear@24 13 std::thread *thread; // array of threads
nuclear@24 14
nuclear@24 15 std::list<std::function<void ()>> workq;
nuclear@24 16 std::mutex workq_mutex;
nuclear@24 17 std::condition_variable condvar;
nuclear@24 18
nuclear@24 19 bool quit;
nuclear@24 20
nuclear@24 21 void thread_func();
nuclear@24 22
nuclear@24 23 public:
nuclear@24 24 ThreadPool(int num_threads = -1);
nuclear@24 25 ~ThreadPool();
nuclear@24 26
nuclear@24 27 void add_work(std::function<void ()> func);
nuclear@24 28 };
nuclear@24 29
nuclear@24 30 #endif // THREAD_POOL_H_