Clean-up
This commit is contained in:
parent
20f6a9a8fd
commit
0e45acf8ce
@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(ThreadPool)
|
||||
add_library(threadpool_lib "src/ThreadPool.cpp")
|
||||
add_library(threadpool_lib "include/ThreadPool.cpp")
|
||||
|
||||
add_executable(${PROJECT_NAME} "main.cpp")
|
||||
|
||||
|
@ -9,14 +9,14 @@
|
||||
#include <vector>
|
||||
|
||||
class ThreadPool {
|
||||
int numOfThreads;
|
||||
long numOfThreads;
|
||||
std::deque<std::function<void()>> _tasks;
|
||||
std::mutex _queueLock;
|
||||
std::atomic<bool> stopped{false};
|
||||
bool startedAlready = false;
|
||||
std::condition_variable _queueCond;
|
||||
std::condition_variable _threadFinishedCond;
|
||||
std::atomic_int numOfThreadsRunning{0};
|
||||
long numOfThreadsRunning = 0;
|
||||
std::vector<std::thread> _threads;
|
||||
|
||||
protected:
|
||||
@ -28,7 +28,7 @@ public:
|
||||
inline ~ThreadPool();
|
||||
inline void push(const std::function<void()> &task);
|
||||
inline void
|
||||
start(const int NumOfThreads = std::thread::hardware_concurrency());
|
||||
start(const long NumOfThreads = std::thread::hardware_concurrency());
|
||||
inline void finish();
|
||||
};
|
||||
|
||||
@ -67,11 +67,10 @@ ThreadPool::~ThreadPool() { this->finish(); }
|
||||
void ThreadPool::push(const std::function<void()> &task) {
|
||||
std::unique_lock<decltype(_queueLock)> lg(_queueLock);
|
||||
_tasks.push_back(task);
|
||||
lg.unlock();
|
||||
_queueCond.notify_one();
|
||||
}
|
||||
|
||||
void ThreadPool::start(const int NumOfThreads) {
|
||||
void ThreadPool::start(const long NumOfThreads) {
|
||||
if (!startedAlready)
|
||||
startedAlready = true;
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user