]> git.sesse.net Git - casparcg/blobdiff - common/concurrency/executor.h
2.0. executor: Removed dangerous code.
[casparcg] / common / concurrency / executor.h
index c4ba4008f95af44af38d5601afed9a238813af0c..31df71fcfc4f50dab9093f314643ed83e53b2131 100644 (file)
 \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
 #include <tbb/concurrent_queue.h>\r
 \r
 #include <boost/thread.hpp>\r
+#include <boost/optional.hpp>\r
 #include <boost/noncopyable.hpp>\r
 \r
 #include <functional>\r
@@ -76,23 +78,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 +162,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
@@ -193,28 +178,7 @@ public:
                                        \r
                return std::move(future);               \r
        }\r
-\r
-       template<typename Func>\r
-       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
-               \r
-               auto future = task_adaptor.value.get_future();\r
-\r
-               if(priority == normal_priority || execution_queue_[normal_priority].try_push(nullptr))\r
-               {                       \r
-                       execution_queue_[priority].try_push([=]\r
-                       {\r
-                               try{task_adaptor.value();}\r
-                               catch(boost::task_already_started&){}\r
-                               catch(...){CASPAR_LOG_CURRENT_EXCEPTION();}\r
-                       });\r
-               }\r
-               \r
-               return std::move(future);                       \r
-       }\r
-\r
+       \r
        template<typename Func>\r
        auto invoke(Func&& func, task_priority prioriy = normal_priority) -> decltype(func()) // noexcept\r
        {\r
@@ -223,16 +187,7 @@ public:
                \r
                return begin_invoke(std::forward<Func>(func), prioriy).get();\r
        }\r
-\r
-       template<typename Func>\r
-       auto try_invoke(Func&& func, task_priority prioriy = normal_priority) -> decltype(func()) // noexcept\r
-       {\r
-               if(boost::this_thread::get_id() == thread_.get_id())  // Avoids potential deadlock.\r
-                       return func();\r
-               \r
-               return try_begin_invoke(std::forward<Func>(func), prioriy).get();\r
-       }\r
-\r
+       \r
        void yield() // noexcept\r
        {\r
                if(boost::this_thread::get_id() != thread_.get_id())  // Only yield when calling from execution thread.\r