]> git.sesse.net Git - casparcg/commitdiff
[executor] Execute remaining tasks at shutdown.
authorHelge Norberg <helge.norberg@svt.se>
Wed, 5 Oct 2016 15:19:42 +0000 (17:19 +0200)
committerHelge Norberg <helge.norberg@svt.se>
Wed, 5 Oct 2016 15:19:42 +0000 (17:19 +0200)
common/executor.h

index d8a34d1373880164c69bb0dd9a94e3eb40481588..d6949615ac360c8b94671568a46eed750178f3db 100644 (file)
@@ -55,11 +55,11 @@ class executor final
 
        typedef blocking_priority_queue<std::function<void()>, task_priority>   function_queue_t;
 
-       const std::wstring                                                                                      name_;
-       tbb::atomic<bool>                                                                                       is_running_;
-       boost::thread                                                                                           thread_;
-       function_queue_t                                                                                        execution_queue_;
-       tbb::atomic<bool>                                                                                       currently_in_task_;
+       const std::wstring      name_;
+       tbb::atomic<bool>       is_running_;
+       boost::thread           thread_;
+       function_queue_t        execution_queue_;
+       tbb::atomic<bool>       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<void()> func;
+
+                       while (execution_queue_.try_pop(func))
+                       {
+                               func();
+                       }
+               }
+               catch (...)
+               {
+                       CASPAR_LOG_CURRENT_EXCEPTION();
+               }
        }
 };
 }