提交 72e49dc7 编写于 作者: A Andrey Kamaev 提交者: OpenCV Buildbot

Merge pull request #777 from taka-no-me:ocl_win_hang

...@@ -913,6 +913,7 @@ namespace cv ...@@ -913,6 +913,7 @@ namespace cv
auto_ptr<Context> Context::clCxt; auto_ptr<Context> Context::clCxt;
int Context::val = 0; int Context::val = 0;
static Mutex cs; static Mutex cs;
static volatile int context_tear_down = 0;
Context* Context::getContext() Context* Context::getContext()
{ {
if(*((volatile int*)&val) != 1) if(*((volatile int*)&val) != 1)
...@@ -920,9 +921,10 @@ namespace cv ...@@ -920,9 +921,10 @@ namespace cv
AutoLock al(cs); AutoLock al(cs);
if(*((volatile int*)&val) != 1) if(*((volatile int*)&val) != 1)
{ {
if (context_tear_down)
return clCxt.get();
if( 0 == clCxt.get()) if( 0 == clCxt.get())
clCxt.reset(new Context); clCxt.reset(new Context);
std::vector<Info> oclinfo; std::vector<Info> oclinfo;
CV_Assert(getDevice(oclinfo, CVCL_DEVICE_TYPE_ALL) > 0); CV_Assert(getDevice(oclinfo, CVCL_DEVICE_TYPE_ALL) > 0);
oclinfo[0].impl->setDevice(0, 0, 0); oclinfo[0].impl->setDevice(0, 0, 0);
...@@ -1045,9 +1047,14 @@ BOOL WINAPI DllMain( HINSTANCE, DWORD fdwReason, LPVOID ) ...@@ -1045,9 +1047,14 @@ BOOL WINAPI DllMain( HINSTANCE, DWORD fdwReason, LPVOID )
{ {
// application hangs if call clReleaseCommandQueue here, so release context only // application hangs if call clReleaseCommandQueue here, so release context only
// without context release application hangs as well // without context release application hangs as well
cl_context ctx = (cl_context)getoclContext(); context_tear_down = 1;
if(ctx) Context* cv_ctx = Context::getContext();
openCLSafeCall(clReleaseContext(ctx)); if(cv_ctx)
{
cl_context ctx = (cl_context)&(cv_ctx->impl->oclcontext);
if(ctx)
openCLSafeCall(clReleaseContext(ctx));
}
} }
return TRUE; return TRUE;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册