Update ThreadPool
This commit is contained in:
parent
4cc2dd6276
commit
ee7ecd8d63
|
@ -1,7 +1,18 @@
|
|||
#include "thread_pool.h"
|
||||
|
||||
struct ThreadWorkerData
|
||||
{
|
||||
std::function<void()> func;
|
||||
std::mutex m;
|
||||
std::condition_variable cond;
|
||||
bool started;
|
||||
bool finished;
|
||||
bool running;
|
||||
};
|
||||
|
||||
using namespace std;
|
||||
|
||||
void _global_thread_worker_main(ThreadWorkerData* ptdd)
|
||||
static void _global_thread_worker_main(ThreadWorkerData* ptdd)
|
||||
{
|
||||
unique_lock<mutex> ulk(ptdd->m);
|
||||
while(ptdd->running)
|
||||
|
|
20
ThreadPool.h
20
ThreadPool.h
|
@ -5,26 +5,20 @@
|
|||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
struct ThreadWorkerData
|
||||
{
|
||||
std::function<void()> func;
|
||||
std::mutex m;
|
||||
std::condition_variable cond;
|
||||
bool started;
|
||||
bool finished;
|
||||
bool running;
|
||||
};
|
||||
|
||||
void _global_thread_worker_main(ThreadWorkerData* ptdd);
|
||||
|
||||
struct ThreadWorkerData;
|
||||
|
||||
class ThreadPool
|
||||
{
|
||||
public:
|
||||
ThreadPool(int n);
|
||||
/// NonCopyable, NonMovable.
|
||||
ThreadPool(const ThreadPool&)=delete;
|
||||
ThreadPool& operator = (const ThreadPool&)=delete;
|
||||
ThreadPool(ThreadPool&&)=delete;
|
||||
ThreadPool& operator = (ThreadPool&&)=delete;
|
||||
~ThreadPool();
|
||||
|
||||
int start(const std::function<void()>& func);
|
||||
int start(const std::function<void()>&);
|
||||
private:
|
||||
std::vector<ThreadWorkerData*> dvec;
|
||||
std::vector<std::thread*> tvec;
|
||||
|
|
Loading…
Reference in New Issue
Block a user