39 lines
675 B
C++
39 lines
675 B
C++
#pragma once
|
|
|
|
#include <pthread.h>
|
|
#include <unistd.h>
|
|
#include <deque>
|
|
#include <iostream>
|
|
#include <vector>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
|
|
#include "Mutex.h"
|
|
#include "Task.h"
|
|
#include "CondVar.h"
|
|
#include "Global.h"
|
|
|
|
namespace sequencelogic
|
|
{
|
|
class ThreadPool
|
|
{
|
|
public:
|
|
ThreadPool();
|
|
ThreadPool(int pool_size);
|
|
~ThreadPool();
|
|
int init();
|
|
int destroy();
|
|
void* executeThread();
|
|
int addTask(Task* task);
|
|
void getTaskCount(int* res);
|
|
void printMsg(std::string msg);
|
|
private:
|
|
int poolSize;
|
|
Mutex taskLock;
|
|
CondVar taskCond;
|
|
std::vector<pthread_t> threads; // storage for threads
|
|
std::deque<Task*> tasks;
|
|
volatile int poolState;
|
|
};
|
|
}
|