X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Fconcurrency%2Fexecutor.h;h=0687889a179a951b0d2e14d82a9162941a4d03dd;hb=a486c25d5e6ce0ebe08e9a2d793a447ff3cb797a;hp=c4ba4008f95af44af38d5601afed9a238813af0c;hpb=8f091990c8e3c1997b4b2d89f97b319cb6ea889d;p=casparcg diff --git a/common/concurrency/executor.h b/common/concurrency/executor.h index c4ba4008f..0687889a1 100644 --- a/common/concurrency/executor.h +++ b/common/concurrency/executor.h @@ -21,6 +21,7 @@ #include "../exception/win32_exception.h" #include "../utility/string.h" +#include "../utility/move_on_copy.h" #include "../log/log.h" #include @@ -76,23 +77,6 @@ enum thread_priority below_normal_priority_class }; -namespace internal -{ - template - struct move_on_copy - { - move_on_copy(const move_on_copy& other) : value(std::move(other.value)){} - move_on_copy(T&& value) : value(std::move(value)){} - mutable T value; - }; - - template - move_on_copy make_move_on_copy(T&& value) - { - return move_on_copy(std::move(value)); - } -} - class executor : boost::noncopyable { const std::string name_; @@ -133,6 +117,7 @@ public: virtual ~executor() // noexcept { stop(); + execution_queue_[normal_priority].try_push([]{}); // Wake the execution thread. join(); } @@ -159,7 +144,6 @@ public: void stop() // noexcept { is_running_ = false; - execution_queue_[normal_priority].try_push([]{}); // Wake the execution thread. } void wait() // noexcept @@ -177,7 +161,7 @@ public: auto begin_invoke(Func&& func, task_priority priority = normal_priority) -> boost::unique_future // noexcept { // Create a move on copy adaptor to avoid copying the functor into the queue, tbb::concurrent_queue does not support move semantics. - auto task_adaptor = internal::make_move_on_copy(create_task(func)); + auto task_adaptor = make_move_on_copy(create_task(func)); auto future = task_adaptor.value.get_future(); @@ -198,7 +182,7 @@ public: auto try_begin_invoke(Func&& func, task_priority priority = normal_priority) -> boost::unique_future // noexcept { // Create a move on copy adaptor to avoid copying the functor into the queue, tbb::concurrent_queue does not support move semantics. - auto task_adaptor = internal::make_move_on_copy(create_task(func)); + auto task_adaptor = make_move_on_copy(create_task(func)); auto future = task_adaptor.value.get_future();