Skip to content

Commit

Permalink
Add methods to retrieve current thread affinity and push contexts
Browse files Browse the repository at this point in the history
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 6c6f646
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions python/core/processing/qgsprocessingcontext.sip
Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions src/core/processing/qgsprocessingcontext.h
Expand Up @@ -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;
Expand Down

0 comments on commit 6c6f646

Please sign in to comment.