Another push variant added

This commit is contained in:
Samer Afach 2019-06-17 12:48:10 +00:00
parent 4e26232e24
commit 7236426a5b

View File

@ -40,6 +40,7 @@ public:
inline ThreadPool(); inline ThreadPool();
inline ~ThreadPool(); inline ~ThreadPool();
inline void push(const std::function<void()> &task); inline void push(const std::function<void()> &task);
inline void push(std::function<void ()> &&task);
inline void inline void
start(const long NumOfThreads = std::thread::hardware_concurrency()); start(const long NumOfThreads = std::thread::hardware_concurrency());
inline void finish(); inline void finish();
@ -83,6 +84,12 @@ void ThreadPool::push(const std::function<void()> &task) {
_queueCond.notify_one(); _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) { void ThreadPool::start(const long NumOfThreads) {
if (!started_already) if (!started_already)
started_already = true; started_already = true;