From: Alexander Alekhin Date: Tue, 10 Dec 2013 20:31:34 +0000 (+0400) Subject: ocl: process termination hung workaround X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~3641^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bdbd3eb2bfe8f1b1da708cb4a349f7e96aa04626;p=platform%2Fupstream%2Fopencv.git ocl: process termination hung workaround --- diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index 0cff7b5..96a006f 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -1932,10 +1932,15 @@ struct Queue::Impl ~Impl() { - if(handle) +#ifdef _WIN32 + if (!cv::__termination) +#endif { - clFinish(handle); - clReleaseCommandQueue(handle); + if(handle) + { + clFinish(handle); + clReleaseCommandQueue(handle); + } } } diff --git a/modules/core/src/precomp.hpp b/modules/core/src/precomp.hpp index 7465685..87104af 100644 --- a/modules/core/src/precomp.hpp +++ b/modules/core/src/precomp.hpp @@ -249,6 +249,9 @@ namespace ocl MatAllocator* getOpenCLAllocator(); } +extern bool __termination; // skip some cleanups, because process is terminating + // (for example, if ExitProcess() was already called) + } #endif /*_CXCORE_INTERNAL_H_*/ diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index eee06e2..2786597 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -734,18 +734,23 @@ cvErrorFromIppStatus( int status ) } } +namespace cv { +bool __termination = false; +} #if defined CVAPI_EXPORTS && defined WIN32 && !defined WINCE #ifdef HAVE_WINRT #pragma warning(disable:4447) // Disable warning 'main' signature found without threading model #endif -BOOL WINAPI DllMain( HINSTANCE, DWORD fdwReason, LPVOID ); +BOOL WINAPI DllMain( HINSTANCE, DWORD, LPVOID ); -BOOL WINAPI DllMain( HINSTANCE, DWORD fdwReason, LPVOID ) +BOOL WINAPI DllMain( HINSTANCE, DWORD fdwReason, LPVOID lpReserved ) { if( fdwReason == DLL_THREAD_DETACH || fdwReason == DLL_PROCESS_DETACH ) { + if (lpReserved != NULL) // called after ExitProcess() call + cv::__termination = true; cv::deleteThreadAllocData(); cv::deleteThreadData(); }