From 918a3b2b7c8e5d897e20f2b2e0f68bbc4099162f Mon Sep 17 00:00:00 2001 From: Maksim Andrianov Date: Wed, 17 Jul 2019 16:19:55 +0300 Subject: [PATCH] [base] Added SubmitWork to ThreadPool --- base/thread_pool_computational.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/base/thread_pool_computational.hpp b/base/thread_pool_computational.hpp index 027a163d0f..03c30b129b 100644 --- a/base/thread_pool_computational.hpp +++ b/base/thread_pool_computational.hpp @@ -84,6 +84,23 @@ public: return result; } + // Submit work for execution. + // func - task to be performed. + // args - arguments for func + // Warning: If the thread pool is stopped then the call will be ignored. + template + void SubmitWork(F && func, Args &&... args) + { + { + std::unique_lock lock(m_mutex); + if (m_done) + return; + + m_queue.emplace(std::bind(std::forward(func), std::forward(args)...)); + } + m_condition.notify_one(); + } + // Stop a ThreadPool. // Removes the tasks that are not yet started from the queue. // Unlike the destructor, this function does not wait for all runnables to complete: