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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -294,14 +294,16 @@ QString QgsOpenClUtils::errorText( const int errorCode )


cl::Context QgsOpenClUtils::context() 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 ); if ( available() && sPlatform() && sDevice() )
} {
else context = cl::Context( sDevice );
{ }
return cl::Context(); } );
} return context;
} }


cl::Program QgsOpenClUtils::buildProgram( const cl::Context &context, const QString &source, ExceptionBehavior exceptionBehavior ) 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.