diff --git a/Parallel/Core/Testing/Cxx/TestThreadedCallbackQueue.cxx b/Parallel/Core/Testing/Cxx/TestThreadedCallbackQueue.cxx index 98944a6c48272b2a56444513733bab34640f5ab4..6818c5fb0d71980ab5437e181d0cbe19ddc2f49a 100644 --- a/Parallel/Core/Testing/Cxx/TestThreadedCallbackQueue.cxx +++ b/Parallel/Core/Testing/Cxx/TestThreadedCallbackQueue.cxx @@ -195,7 +195,7 @@ bool TestSharedFutures() for (auto& future : futures) { - retVal &= future->Get(); + retVal &= queue->Get(future); } } diff --git a/Parallel/Core/vtkThreadedCallbackQueue.h b/Parallel/Core/vtkThreadedCallbackQueue.h index 6d85591d1038ebf0057205f63ff840aa18a07466..7e92640fbe4245c4e975bf00a17d74b36ca5288a 100644 --- a/Parallel/Core/vtkThreadedCallbackQueue.h +++ b/Parallel/Core/vtkThreadedCallbackQueue.h @@ -271,6 +271,22 @@ public: template <class SharedFutureContainerT> void Wait(SharedFutureContainerT&& priorSharedFuture); + ///@{ + /** + * Get the returned value from the task associated with the input future. + * It effectlively calls `Wait`. If the task has not started yet upon the call of this function, + * then the current thread will run the task itself. + * + * This function returns `void` if `ReturnT` is void. It returns `ReturnT&` or `const ReturnT&` + * otherwise. + */ + template <class ReturnT> + typename vtkSharedFuture<ReturnT>::ReturnLValueRef Get(SharedFuturePointer<ReturnT>& future); + template <class ReturnT> + typename vtkSharedFuture<ReturnT>::ReturnConstLValueRef Get( + const SharedFuturePointer<ReturnT>& future); + ///@} + /** * Sets the number of threads. The running state of the queue is not impacted by this method. * diff --git a/Parallel/Core/vtkThreadedCallbackQueue.txx b/Parallel/Core/vtkThreadedCallbackQueue.txx index 21187394c4739079ed905a9867e9abe583355e49..556f33e675ec4cb659d446df50eb44071398cf2e 100644 --- a/Parallel/Core/vtkThreadedCallbackQueue.txx +++ b/Parallel/Core/vtkThreadedCallbackQueue.txx @@ -15,8 +15,7 @@ #include "vtkObjectFactory.h" -#include "vtkLogger.h" - +#include <array> #include <cassert> #include <stdexcept> #include <tuple> @@ -711,6 +710,24 @@ void vtkThreadedCallbackQueue::Wait(SharedFutureContainerT&& priorSharedFutures) pair.second->Wait(); } +//----------------------------------------------------------------------------- +template <class ReturnT> +typename vtkThreadedCallbackQueue::vtkSharedFuture<ReturnT>::ReturnLValueRef +vtkThreadedCallbackQueue::Get(SharedFuturePointer<ReturnT>& future) +{ + this->Wait(std::array<vtkSharedFuture<ReturnT>*, 1>{ future }); + return future->Get(); +} + +//----------------------------------------------------------------------------- +template <class ReturnT> +typename vtkThreadedCallbackQueue::vtkSharedFuture<ReturnT>::ReturnConstLValueRef +vtkThreadedCallbackQueue::Get(const SharedFuturePointer<ReturnT>& future) +{ + this->Wait(std::array<vtkSharedFuture<ReturnT>*, 1>{ future }); + return future->Get(); +} + //----------------------------------------------------------------------------- template <class SharedFutureContainerT, class FT, class... ArgsT> vtkThreadedCallbackQueue::SharedFuturePointer<vtkThreadedCallbackQueue::InvokeResult<FT>>