1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

core(tls): implement releasing of TLS on thread termination

- move TLS & instrumentation code out of core/utility.hpp
- (*) TLSData lost .gather() method (to dispose thread data on thread termination)
- use TLSDataAccumulator for reliable collecting of thread data
- prefer using of .detachData() + .cleanupDetachedData() instead of .gather() method

(*) API is broken: replace TLSData => TLSDataAccumulator if gather required
(objects disposal on threads termination is not available in accumulator mode)
This commit is contained in:
Alexander Alekhin
2019-10-13 11:14:41 +00:00
parent dd4f591d54
commit 17e2bf5717
14 changed files with 650 additions and 239 deletions
+13 -12
View File
@@ -909,19 +909,19 @@ bool haveOpenCL()
bool useOpenCL()
{
CoreTLSData* data = getCoreTlsData().get();
if( data->useOpenCL < 0 )
CoreTLSData& data = getCoreTlsData();
if (data.useOpenCL < 0)
{
try
{
data->useOpenCL = (int)(haveOpenCL() && Device::getDefault().ptr() && Device::getDefault().available()) ? 1 : 0;
data.useOpenCL = (int)(haveOpenCL() && Device::getDefault().ptr() && Device::getDefault().available()) ? 1 : 0;
}
catch (...)
{
data->useOpenCL = 0;
data.useOpenCL = 0;
}
}
return data->useOpenCL > 0;
return data.useOpenCL > 0;
}
#ifdef HAVE_OPENCL
@@ -937,14 +937,14 @@ void setUseOpenCL(bool flag)
{
CV_TRACE_FUNCTION();
CoreTLSData* data = getCoreTlsData().get();
CoreTLSData& data = getCoreTlsData();
if (!flag)
{
data->useOpenCL = 0;
data.useOpenCL = 0;
}
else if( haveOpenCL() )
{
data->useOpenCL = (Device::getDefault().ptr() != NULL) ? 1 : 0;
data.useOpenCL = (Device::getDefault().ptr() != NULL) ? 1 : 0;
}
}
@@ -1655,7 +1655,7 @@ size_t Device::profilingTimerResolution() const
const Device& Device::getDefault()
{
const Context& ctx = Context::getDefault();
int idx = getCoreTlsData().get()->device;
int idx = getCoreTlsData().device;
const Device& device = ctx.device(idx);
return device;
}
@@ -2562,9 +2562,10 @@ void attachContext(const String& platformName, void* platformID, void* context,
CV_OCL_CHECK(clRetainContext((cl_context)context));
// clear command queue, if any
getCoreTlsData().get()->oclQueue.finish();
CoreTLSData& data = getCoreTlsData();
data.oclQueue.finish();
Queue q;
getCoreTlsData().get()->oclQueue = q;
data.oclQueue = q;
return;
} // attachContext()
@@ -2752,7 +2753,7 @@ void* Queue::ptr() const
Queue& Queue::getDefault()
{
Queue& q = getCoreTlsData().get()->oclQueue;
Queue& q = getCoreTlsData().oclQueue;
if( !q.p && haveOpenCL() )
q.create(Context::getDefault());
return q;