Another push variant added

This commit is contained in:
Samer Afach 2019-06-17 12:48:10 +00:00
parent 4e26232e24
commit 7236426a5b
1 changed files with 7 additions and 0 deletions

View File

@ -40,6 +40,7 @@ public:
inline ThreadPool();
inline ~ThreadPool();
inline void push(const std::function<void()> &task);
inline void push(std::function<void ()> &&task);
inline void
start(const long NumOfThreads = std::thread::hardware_concurrency());
inline void finish();
@ -83,6 +84,12 @@ void ThreadPool::push(const std::function<void()> &task) {
_queueCond.notify_one();
}
void ThreadPool::push(std::function<void ()>&& task) {
std::unique_lock<decltype(_queueLock)> lg(_queueLock);
_tasks.push_back(std::move(task));
_queueCond.notify_one();
}
void ThreadPool::start(const long NumOfThreads) {
if (!started_already)
started_already = true;