Skip to content

Commit

Permalink
[opencl] Cache the context
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Aug 8, 2018
1 parent e29c7e5 commit 54b5821
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/core/qgsopenclutils.cpp
Expand Up @@ -294,14 +294,16 @@ QString QgsOpenClUtils::errorText( const int errorCode )

cl::Context QgsOpenClUtils::context()
{
if ( available() && sPlatform() && sDevice() )
static cl::Context context;
static std::once_flag contextCreated;
std::call_once( contextCreated, [ = ]()
{
return cl::Context( sDevice );
}
else
{
return cl::Context();
}
if ( available() && sPlatform() && sDevice() )
{
context = cl::Context( sDevice );
}
} );
return context;
}

cl::Program QgsOpenClUtils::buildProgram( const cl::Context &context, const QString &source, ExceptionBehavior exceptionBehavior )
Expand Down

0 comments on commit 54b5821

Please sign in to comment.