]> git.sesse.net Git - casparcg/blobdiff - common/concurrency/executor.h
2.0 image_mixer: Refactored, core: Fixed destruction proxy usage.
[casparcg] / common / concurrency / executor.h
index c4ba4008f95af44af38d5601afed9a238813af0c..0687889a179a951b0d2e14d82a9162941a4d03dd 100644 (file)
@@ -21,6 +21,7 @@
 \r
 #include "../exception/win32_exception.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
@@ -133,6 +117,7 @@ public:
        virtual ~executor() // noexcept\r
        {\r
                stop();\r
+               execution_queue_[normal_priority].try_push([]{}); // Wake the execution thread.\r
                join();\r
        }\r
 \r
@@ -159,7 +144,6 @@ public:
        void stop() // noexcept\r
        {\r
                is_running_ = false;    \r
-               execution_queue_[normal_priority].try_push([]{}); // Wake the execution thread.\r
        }\r
 \r
        void wait() // noexcept\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