]> git.sesse.net Git - casparcg/blobdiff - common/concurrency/executor.h
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
[casparcg] / common / concurrency / executor.h
index 45c452f261348e8922b6e346b8d757ec5c443115..ad86d4a379358f11083f56df523ba66b7f703e45 100644 (file)
@@ -20,7 +20,8 @@
 #pragma once\r
 \r
 #include "../exception/win32_exception.h"\r
-#include "../utility/assert.h"\r
+#include "../utility/string.h"\r
+#include "../utility/move_on_copy.h"\r
 #include "../log/log.h"\r
 \r
 #include <tbb/atomic.h>\r
@@ -76,23 +77,6 @@ enum thread_priority
        below_normal_priority_class\r
 };\r
 \r
-namespace internal\r
-{\r
-       template<typename T>\r
-       struct move_on_copy\r
-       {\r
-               move_on_copy(const move_on_copy<T>& other) : value(std::move(other.value)){}\r
-               move_on_copy(T&& value) : value(std::move(value)){}\r
-               mutable T value;\r
-       };\r
-\r
-       template<typename T>\r
-       move_on_copy<T> make_move_on_copy(T&& value)\r
-       {\r
-               return move_on_copy<T>(std::move(value));\r
-       }\r
-}\r
-\r
 class executor : boost::noncopyable\r
 {\r
        const std::string name_;\r
@@ -177,7 +161,7 @@ public:
        auto begin_invoke(Func&& func, task_priority priority = normal_priority) -> boost::unique_future<decltype(func())> // noexcept\r
        {       \r
                // Create a move on copy adaptor to avoid copying the functor into the queue, tbb::concurrent_queue does not support move semantics.\r
-               auto task_adaptor = internal::make_move_on_copy(create_task(func));\r
+               auto task_adaptor = make_move_on_copy(create_task(func));\r
 \r
                auto future = task_adaptor.value.get_future();\r
 \r
@@ -198,7 +182,7 @@ public:
        auto try_begin_invoke(Func&& func, task_priority priority = normal_priority) -> boost::unique_future<decltype(func())> // noexcept\r
        {\r
                // Create a move on copy adaptor to avoid copying the functor into the queue, tbb::concurrent_queue does not support move semantics.\r
-               auto task_adaptor = internal::make_move_on_copy(create_task(func));\r
+               auto task_adaptor = make_move_on_copy(create_task(func));\r
                \r
                auto future = task_adaptor.value.get_future();\r
 \r
@@ -208,11 +192,7 @@ public:
                        {\r
                                try{task_adaptor.value();}\r
                                catch(boost::task_already_started&){}\r
-                               catch(...)\r
-                               {\r
-                                       CASPAR_LOG_CURRENT_EXCEPTION();\r
-                                       throw;\r
-                               }\r
+                               catch(...){CASPAR_LOG_CURRENT_EXCEPTION();}\r
                        });\r
                }\r
                \r
@@ -273,7 +253,16 @@ private:
                win32_exception::install_handler();             \r
                detail::SetThreadName(GetCurrentThreadId(), name_.c_str());\r
                while(is_running_)\r
-                       execute();\r
+               {\r
+                       try\r
+                       {\r
+                               execute();\r
+                       }\r
+                       catch(...)\r
+                       {\r
+                               CASPAR_LOG_CURRENT_EXCEPTION();\r
+                       }\r
+               }\r
        }       \r
 };\r
 \r