mirror of
https://github.com/opencv/opencv.git
synced 2025-06-12 20:42:53 +08:00
gapi(async): use lazy-initialization of async_service singleton
This commit is contained in:
parent
84676fefe3
commit
e43375cc68
@ -37,9 +37,16 @@ class async_service {
|
|||||||
|
|
||||||
std::thread thrd;
|
std::thread thrd;
|
||||||
|
|
||||||
public:
|
|
||||||
async_service() = default ;
|
async_service() = default ;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// singleton
|
||||||
|
static async_service& instance()
|
||||||
|
{
|
||||||
|
static async_service the_ctx;
|
||||||
|
return the_ctx;
|
||||||
|
}
|
||||||
|
|
||||||
void add_task(std::function<void()>&& t){
|
void add_task(std::function<void()>&& t){
|
||||||
if (!thread_started)
|
if (!thread_started)
|
||||||
{
|
{
|
||||||
@ -87,6 +94,8 @@ public:
|
|||||||
cv.notify_one();
|
cv.notify_one();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
~async_service(){
|
~async_service(){
|
||||||
if (thread_started && thrd.joinable())
|
if (thread_started && thrd.joinable())
|
||||||
{
|
{
|
||||||
@ -99,7 +108,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async_service the_ctx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -169,7 +177,7 @@ void async_apply(GComputation& gcomp, std::function<void(std::exception_ptr)>&&
|
|||||||
|
|
||||||
call_with_callback(apply_l,std::move(callback), DummyContext{});
|
call_with_callback(apply_l,std::move(callback), DummyContext{});
|
||||||
};
|
};
|
||||||
impl::the_ctx.add_task(l);
|
impl::async_service::instance().add_task(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
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){
|
||||||
@ -183,7 +191,7 @@ std::future<void> async_apply(GComputation& gcomp, GRunArgs &&ins, GRunArgsP &&o
|
|||||||
call_with_future(apply_l, prms.value, DummyContext{});
|
call_with_future(apply_l, prms.value, DummyContext{});
|
||||||
};
|
};
|
||||||
|
|
||||||
impl::the_ctx.add_task(l);
|
impl::async_service::instance().add_task(l);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +204,7 @@ void async_apply(GComputation& gcomp, std::function<void(std::exception_ptr)>&&
|
|||||||
|
|
||||||
call_with_callback(apply_l,std::move(callback), ctx);
|
call_with_callback(apply_l,std::move(callback), ctx);
|
||||||
};
|
};
|
||||||
impl::the_ctx.add_task(l);
|
impl::async_service::instance().add_task(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
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){
|
||||||
@ -210,7 +218,7 @@ std::future<void> async_apply(GComputation& gcomp, GRunArgs &&ins, GRunArgsP &&o
|
|||||||
call_with_future(apply_l, prms.value, ctx);
|
call_with_future(apply_l, prms.value, ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
impl::the_ctx.add_task(l);
|
impl::async_service::instance().add_task(l);
|
||||||
return f;
|
return f;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -224,7 +232,7 @@ void async(GCompiled& gcmpld, std::function<void(std::exception_ptr)>&& callback
|
|||||||
call_with_callback(apply_l,std::move(callback), DummyContext{});
|
call_with_callback(apply_l,std::move(callback), DummyContext{});
|
||||||
};
|
};
|
||||||
|
|
||||||
impl::the_ctx.add_task(l);
|
impl::async_service::instance().add_task(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
void async(GCompiled& gcmpld, std::function<void(std::exception_ptr)>&& callback, GRunArgs &&ins, GRunArgsP &&outs, GAsyncContext& ctx){
|
void async(GCompiled& gcmpld, std::function<void(std::exception_ptr)>&& callback, GRunArgs &&ins, GRunArgsP &&outs, GAsyncContext& ctx){
|
||||||
@ -236,7 +244,7 @@ void async(GCompiled& gcmpld, std::function<void(std::exception_ptr)>&& callback
|
|||||||
call_with_callback(apply_l,std::move(callback), ctx);
|
call_with_callback(apply_l,std::move(callback), ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
impl::the_ctx.add_task(l);
|
impl::async_service::instance().add_task(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::future<void> async(GCompiled& gcmpld, GRunArgs &&ins, GRunArgsP &&outs){
|
std::future<void> async(GCompiled& gcmpld, GRunArgs &&ins, GRunArgsP &&outs){
|
||||||
@ -250,7 +258,7 @@ std::future<void> async(GCompiled& gcmpld, GRunArgs &&ins, GRunArgsP &&outs){
|
|||||||
call_with_future(apply_l, prms.value, DummyContext{});
|
call_with_future(apply_l, prms.value, DummyContext{});
|
||||||
};
|
};
|
||||||
|
|
||||||
impl::the_ctx.add_task(l);
|
impl::async_service::instance().add_task(l);
|
||||||
return f;
|
return f;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -265,7 +273,7 @@ std::future<void> async(GCompiled& gcmpld, GRunArgs &&ins, GRunArgsP &&outs, GAs
|
|||||||
call_with_future(apply_l, prms.value, ctx);
|
call_with_future(apply_l, prms.value, ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
impl::the_ctx.add_task(l);
|
impl::async_service::instance().add_task(l);
|
||||||
return f;
|
return f;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user