lokinet/llarp/threadpool.hpp

40 lines
745 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>
namespace llarp
{
namespace thread
{
typedef std::mutex mtx_t;
typedef std::unique_lock< mtx_t > lock_t;
struct Pool
{
Pool(size_t sz, const char* name);
void
QueueJob(const llarp_thread_job& job);
void
Join();
void
Stop();
std::vector< std::thread > threads;
std::deque< llarp_thread_job > jobs;
2018-01-29 14:27:24 +00:00
mtx_t queue_mutex;
std::condition_variable condition;
std::condition_variable done;
bool stop;
};
2018-01-29 14:19:00 +00:00
} // namespace thread
2018-02-01 13:21:00 +00:00
} // namespace llarp
2018-01-29 14:19:00 +00:00
#endif