lokinet/llarp/threadpool.hpp

34 lines
637 B
C++
Raw Normal View History

2018-01-29 14:19:00 +00:00
#ifndef LLARP_THREADPOOL_HPP
#define LLARP_THREADPOOL_HPP
#include <llarp/threadpool.h>
#include <condition_variable>
2018-02-18 18:45:06 +00:00
#include <deque>
2018-02-21 00:11:26 +00:00
#include <mutex>
2018-01-29 14:27:24 +00:00
#include <thread>
2018-01-29 14:19:00 +00:00
#include <vector>
2018-01-29 14:27:24 +00:00
namespace llarp {
namespace thread {
typedef std::mutex mtx_t;
typedef std::unique_lock<mtx_t> lock_t;
struct Pool {
Pool(size_t sz);
2018-02-21 00:11:26 +00:00
void QueueJob(const llarp_thread_job& job);
2018-01-29 14:27:24 +00:00
void Join();
2018-04-30 14:57:13 +00:00
void Stop();
2018-01-29 14:27:24 +00:00
std::vector<std::thread> threads;
2018-02-18 18:45:06 +00:00
std::deque<llarp_thread_job> jobs;
2018-01-29 14:27:24 +00:00
mtx_t queue_mutex;
std::condition_variable condition;
2018-04-30 14:57:13 +00:00
std::condition_variable done;
2018-02-01 13:21:00 +00:00
bool stop;
2018-01-29 14:27:24 +00:00
};
2018-01-29 14:19:00 +00:00
2018-02-01 13:21:00 +00:00
} // namespace thread
} // namespace llarp
2018-01-29 14:19:00 +00:00
#endif