12#ifndef vtkSMPThreadPool_h
13#define vtkSMPThreadPool_h
15#include "vtkCommonCoreModule.h"
30VTK_ABI_NAMESPACE_BEGIN
45 struct ProxyThreadData;
59 class VTKCOMMONCORE_EXPORT
Proxy final
99 Proxy(
std::unique_ptr<ProxyData>&& data);
101 std::unique_ptr<ProxyData> Data;
158 static
void RunJob(ThreadData& data,
std::
size_t jobIndex,
std::unique_lock<
std::mutex>& lock);
160 ThreadData* GetCallerThreadData() const noexcept;
162 std::thread MakeThread();
163 void FillThreadsForNestedProxy(ProxyData* proxy,
std::
size_t maxCount);
164 std::
size_t GetNextThreadId() noexcept;
166 std::atomic<
bool> Initialized{};
167 std::atomic<bool> Joining{};
168 std::vector<std::unique_ptr<ThreadData>> Threads;
169 std::atomic<std::size_t> NextProxyThreadId{ 1 };
Proxy class used to submit work to the thread pool.
std::vector< std::reference_wrapper< std::thread > > GetThreads() const
Get a reference on all system threads used by this proxy.
void DoJob(std::function< void()> job)
Add a job to the thread pool queue.
Proxy(const Proxy &)=delete
void Join()
Blocks calling thread until all jobs are done.
friend class vtkSMPThreadPool
Proxy & operator=(const Proxy &)=delete
bool IsTopLevel() const noexcept
Return true is this proxy is allocated from a thread that does not belong to the pool.
bool IsParallelScope() const noexcept
Returns true when called from a proxy thread, false otherwise.
static constexpr std::size_t ExternalThreadID
Value returned by GetThreadID when called by a thread that does not belong to the pool.
bool GetSingleThread() const
Returns true for a single proxy thread, false for the others.
static vtkSMPThreadPool & GetInstance()
std::size_t ThreadCount() const noexcept
Returns number of system thread used by the thread pool.
std::size_t GetThreadId() const noexcept
Get caller proxy thread virtual ID.
Proxy AllocateThreads(std::size_t threadCount=0)
Create a proxy.
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.