From 01580e0cc6015d4c198bec570be29129e78c657f Mon Sep 17 00:00:00 2001 From: Helge Norberg Date: Wed, 5 Oct 2016 17:19:42 +0200 Subject: [PATCH] [executor] Execute remaining tasks at shutdown. --- common/executor.h | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/common/executor.h b/common/executor.h index d8a34d137..d6949615a 100644 --- a/common/executor.h +++ b/common/executor.h @@ -55,11 +55,11 @@ class executor final typedef blocking_priority_queue, task_priority> function_queue_t; - const std::wstring name_; - tbb::atomic is_running_; - boost::thread thread_; - function_queue_t execution_queue_; - tbb::atomic currently_in_task_; + const std::wstring name_; + tbb::atomic is_running_; + boost::thread thread_; + function_queue_t execution_queue_; + tbb::atomic currently_in_task_; public: executor(const std::wstring& name) @@ -276,7 +276,7 @@ private: void run() // noexcept { ensure_gpf_handler_installed_for_thread(u8(name_).c_str()); - while(is_running_) + while (is_running_) { try { @@ -285,13 +285,28 @@ private: currently_in_task_ = true; func(); } - catch(...) + catch (...) { CASPAR_LOG_CURRENT_EXCEPTION(); } currently_in_task_ = false; } + + // Execute rest + try + { + std::function func; + + while (execution_queue_.try_pop(func)) + { + func(); + } + } + catch (...) + { + CASPAR_LOG_CURRENT_EXCEPTION(); + } } }; } -- 2.39.2