Skip to content
Permalink
Browse files

Add methods to retrieve current thread affinity and push contexts

to another thread

With suitable assert in place to ensure that pushes are only
made when current thread == existing thread affinity
  • Loading branch information
nyalldawson committed Jul 6, 2017
1 parent 1dce459 commit 6c6f646291c6fb512911e8144427640a9bcef253
Showing with 33 additions and 0 deletions.
  1. +15 −0 python/core/processing/qgsprocessingcontext.sip
  2. +18 −0 src/core/processing/qgsprocessingcontext.h
@@ -214,6 +214,21 @@ Destination project
and no errors will occur if feedback is deleted before the context.
Ownership of ``feedback`` is not transferred.
.. seealso:: setFeedback()
%End

QThread *thread();
%Docstring
Returns the thread in which the context lives.
.. seealso:: pushToThread()
:rtype: QThread
%End

void pushToThread( QThread *thread );
%Docstring
Pushes the thread affinity for the context (including all layers contained in the temporaryLayerStore()) into
another ``thread``. This method is only safe to call when the current thread matches the existing thread
affinity for the context (see thread()).
.. seealso:: thread()
%End

private:
@@ -310,6 +310,24 @@ class CORE_EXPORT QgsProcessingContext
*/
void setFeedback( QgsProcessingFeedback *feedback ) { mFeedback = feedback; }

/**
* Returns the thread in which the context lives.
* \see pushToThread()
*/
QThread *thread() { return tempLayerStore.thread(); }

/**
* Pushes the thread affinity for the context (including all layers contained in the temporaryLayerStore()) into
* another \a thread. This method is only safe to call when the current thread matches the existing thread
* affinity for the context (see thread()).
* \see thread()
*/
void pushToThread( QThread *thread )
{
Q_ASSERTX( QThread::currentThread() == thread(), "QgsProcessingContext::pushToThread", "Cannot push context to another thread unless the current thread matches the existing context thread affinity" );
tempLayerStore.moveToThread( thread );
}

private:

QgsProcessingContext::Flags mFlags = 0;

0 comments on commit 6c6f646

Please sign in to comment.
You can’t perform that action at this time.