From 43f6e137b38378a22702cbfdbe9921defbe3d94b Mon Sep 17 00:00:00 2001 From: Maksim Andrianov Date: Wed, 17 Jul 2019 17:59:05 +0300 Subject: [PATCH] Review fixes --- base/thread_pool_computational.hpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/base/thread_pool_computational.hpp b/base/thread_pool_computational.hpp index 03c30b129b..97feb0e9ac 100644 --- a/base/thread_pool_computational.hpp +++ b/base/thread_pool_computational.hpp @@ -67,18 +67,16 @@ public: template auto Submit(F && func, Args &&... args) -> std::future { - { - std::unique_lock lock(m_mutex); - if (m_done) - return {}; - } using ResultType = decltype(func(args...)); std::packaged_task task(std::bind(std::forward(func), std::forward(args)...)); std::future result(task.get_future()); { std::unique_lock lock(m_mutex); - m_queue.emplace(std::move(task)); + if (m_done) + return {}; + + m_queue.emplace(std::move(task)); } m_condition.notify_one(); return result; @@ -91,12 +89,13 @@ public: template void SubmitWork(F && func, Args &&... args) { + auto f = std::bind(std::forward(func), std::forward(args)...); { std::unique_lock lock(m_mutex); if (m_done) return; - m_queue.emplace(std::bind(std::forward(func), std::forward(args)...)); + m_queue.emplace(std::move(f)); } m_condition.notify_one(); }