|
|
@ -11,6 +11,8 @@ |
|
|
|
#include <opencv2/gapi/gcompiled.hpp> |
|
|
|
#include <opencv2/gapi/gcompiled.hpp> |
|
|
|
#include <opencv2/gapi/gasync_context.hpp> |
|
|
|
#include <opencv2/gapi/gasync_context.hpp> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <opencv2/gapi/util/copy_through_move.hpp> |
|
|
|
|
|
|
|
|
|
|
|
#include <condition_variable> |
|
|
|
#include <condition_variable> |
|
|
|
|
|
|
|
|
|
|
|
#include <future> |
|
|
|
#include <future> |
|
|
@ -18,16 +20,6 @@ |
|
|
|
#include <stdexcept> |
|
|
|
#include <stdexcept> |
|
|
|
#include <queue> |
|
|
|
#include <queue> |
|
|
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
|
|
|
//This is a tool to move initialize captures of a lambda in C++11
|
|
|
|
|
|
|
|
template<typename T> |
|
|
|
|
|
|
|
struct copy_through_move{ |
|
|
|
|
|
|
|
T value; |
|
|
|
|
|
|
|
copy_through_move(T&& g) : value(std::move(g)) {} |
|
|
|
|
|
|
|
copy_through_move(copy_through_move&&) = default; |
|
|
|
|
|
|
|
copy_through_move(copy_through_move const& lhs) : copy_through_move(std::move(const_cast<copy_through_move&>(lhs))) {} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace cv { |
|
|
|
namespace cv { |
|
|
|
namespace gapi { |
|
|
|
namespace gapi { |
|
|
@ -168,7 +160,7 @@ const char* GAsyncCanceled::what() const noexcept { |
|
|
|
//For now these async functions are simply wrapping serial version of apply/operator() into a functor.
|
|
|
|
//For now these async functions are simply wrapping serial version of apply/operator() into a functor.
|
|
|
|
//These functors are then serialized into single queue, which is processed by a devoted background thread.
|
|
|
|
//These functors are then serialized into single queue, which is processed by a devoted background thread.
|
|
|
|
void async_apply(GComputation& gcomp, std::function<void(std::exception_ptr)>&& callback, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args){ |
|
|
|
void async_apply(GComputation& gcomp, std::function<void(std::exception_ptr)>&& callback, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args){ |
|
|
|
//TODO: use copy_through_move for all args except gcomp
|
|
|
|
//TODO: use copy_through_move_t for all args except gcomp
|
|
|
|
//TODO: avoid code duplication between versions of "async" functions
|
|
|
|
//TODO: avoid code duplication between versions of "async" functions
|
|
|
|
auto l = [=]() mutable { |
|
|
|
auto l = [=]() mutable { |
|
|
|
auto apply_l = [&](){ |
|
|
|
auto apply_l = [&](){ |
|
|
@ -181,7 +173,7 @@ void async_apply(GComputation& gcomp, std::function<void(std::exception_ptr)>&& |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::future<void> async_apply(GComputation& gcomp, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args){ |
|
|
|
std::future<void> async_apply(GComputation& gcomp, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args){ |
|
|
|
copy_through_move<std::promise<void>> prms{{}}; |
|
|
|
util::copy_through_move_t<std::promise<void>> prms{{}}; |
|
|
|
auto f = prms.value.get_future(); |
|
|
|
auto f = prms.value.get_future(); |
|
|
|
auto l = [=]() mutable { |
|
|
|
auto l = [=]() mutable { |
|
|
|
auto apply_l = [&](){ |
|
|
|
auto apply_l = [&](){ |
|
|
@ -196,7 +188,7 @@ std::future<void> async_apply(GComputation& gcomp, GRunArgs &&ins, GRunArgsP &&o |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void async_apply(GComputation& gcomp, std::function<void(std::exception_ptr)>&& callback, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args, GAsyncContext& ctx){ |
|
|
|
void async_apply(GComputation& gcomp, std::function<void(std::exception_ptr)>&& callback, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args, GAsyncContext& ctx){ |
|
|
|
//TODO: use copy_through_move for all args except gcomp
|
|
|
|
//TODO: use copy_through_move_t for all args except gcomp
|
|
|
|
auto l = [=, &ctx]() mutable { |
|
|
|
auto l = [=, &ctx]() mutable { |
|
|
|
auto apply_l = [&](){ |
|
|
|
auto apply_l = [&](){ |
|
|
|
gcomp.apply(std::move(ins), std::move(outs), std::move(args)); |
|
|
|
gcomp.apply(std::move(ins), std::move(outs), std::move(args)); |
|
|
@ -208,7 +200,7 @@ void async_apply(GComputation& gcomp, std::function<void(std::exception_ptr)>&& |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::future<void> async_apply(GComputation& gcomp, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args, GAsyncContext& ctx){ |
|
|
|
std::future<void> async_apply(GComputation& gcomp, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args, GAsyncContext& ctx){ |
|
|
|
copy_through_move<std::promise<void>> prms{{}}; |
|
|
|
util::copy_through_move_t<std::promise<void>> prms{{}}; |
|
|
|
auto f = prms.value.get_future(); |
|
|
|
auto f = prms.value.get_future(); |
|
|
|
auto l = [=, &ctx]() mutable { |
|
|
|
auto l = [=, &ctx]() mutable { |
|
|
|
auto apply_l = [&](){ |
|
|
|
auto apply_l = [&](){ |
|
|
@ -248,7 +240,7 @@ void async(GCompiled& gcmpld, std::function<void(std::exception_ptr)>&& callback |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::future<void> async(GCompiled& gcmpld, GRunArgs &&ins, GRunArgsP &&outs){ |
|
|
|
std::future<void> async(GCompiled& gcmpld, GRunArgs &&ins, GRunArgsP &&outs){ |
|
|
|
copy_through_move<std::promise<void>> prms{{}}; |
|
|
|
util::copy_through_move_t<std::promise<void>> prms{{}}; |
|
|
|
auto f = prms.value.get_future(); |
|
|
|
auto f = prms.value.get_future(); |
|
|
|
auto l = [=]() mutable { |
|
|
|
auto l = [=]() mutable { |
|
|
|
auto apply_l = [&](){ |
|
|
|
auto apply_l = [&](){ |
|
|
@ -263,7 +255,7 @@ std::future<void> async(GCompiled& gcmpld, GRunArgs &&ins, GRunArgsP &&outs){ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
std::future<void> async(GCompiled& gcmpld, GRunArgs &&ins, GRunArgsP &&outs, GAsyncContext& ctx){ |
|
|
|
std::future<void> async(GCompiled& gcmpld, GRunArgs &&ins, GRunArgsP &&outs, GAsyncContext& ctx){ |
|
|
|
copy_through_move<std::promise<void>> prms{{}}; |
|
|
|
util::copy_through_move_t<std::promise<void>> prms{{}}; |
|
|
|
auto f = prms.value.get_future(); |
|
|
|
auto f = prms.value.get_future(); |
|
|
|
auto l = [=, &ctx]() mutable { |
|
|
|
auto l = [=, &ctx]() mutable { |
|
|
|
auto apply_l = [&](){ |
|
|
|
auto apply_l = [&](){ |
|
|
|