1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

ocl: fixes for OpenCL multiple contexts support

This commit is contained in:
Alexander Alekhin
2020-09-03 07:41:03 +00:00
parent 2129c72bc0
commit 8711653530
4 changed files with 13 additions and 7 deletions
+5 -4
View File
@@ -2316,8 +2316,9 @@ struct Context::Impl
typedef std::deque<Context::Impl*> container_t;
static container_t& getGlobalContainer()
{
static container_t g_contexts;
return g_contexts;
// never delete this container (Impl lifetime is greater due to TLS storage)
static container_t* g_contexts = new container_t();
return *g_contexts;
}
protected:
@@ -2356,7 +2357,7 @@ protected:
{
cv::AutoLock lock(cv::getInitializationMutex());
auto& container = getGlobalContainer();
CV_Assert((size_t)contextId < container.size());
CV_CheckLT((size_t)contextId, container.size(), "");
container[contextId] = NULL;
}
}
@@ -2839,7 +2840,7 @@ bool Context::create()
if (!haveOpenCL())
return false;
p = Impl::findOrCreateContext(std::string());
if (p->handle)
if (p && p->handle)
return true;
release();
return false;