7#ifndef PXR_BASE_WORK_DISPATCHER_H
8#define PXR_BASE_WORK_DISPATCHER_H
13#include "pxr/base/work/api.h"
14#include "pxr/base/work/impl.h"
25PXR_NAMESPACE_OPEN_SCOPE
36 WORK_API Work_Dispatcher();
40 WORK_API ~Work_Dispatcher() noexcept;
42 Work_Dispatcher(Work_Dispatcher const &) = delete;
43 Work_Dispatcher &operator=(Work_Dispatcher const &) = delete;
57 template <
class Callable,
class A1,
class A2, ...
class AN>
58 void Run(Callable &&c, A1 &&a1, A2 &&a2, ... AN &&aN);
62 template <
class Callable>
63 inline void Run(Callable &&c) {
66 _MallocTagsInvokerTask<
67 typename std::remove_reference<Callable>::type>(
68 std::forward<Callable>(c), &_diagnostics));
72 _InvokerTask<
typename std::remove_reference<Callable>::type>(
73 std::forward<Callable>(c), &_diagnostics));
77 template <
class Callable,
class A0,
class ... Args>
78 inline void Run(Callable &&c, A0 &&a0, Args&&... args) {
79 Run(std::bind(std::forward<Callable>(c),
81 std::forward<Args>(args)...));
99 WORK_API
void Cancel();
103 WORK_API
bool IsCancelled()
const;
106 typedef tbb::concurrent_vector<TfDiagnosticTransport> _DiagnosticTransports;
112 struct _InvokerTask {
113 explicit _InvokerTask(Fn &&fn, _DiagnosticTransports *diag)
115 , _diagnostics(diag) {}
117 explicit _InvokerTask(Fn
const &fn, _DiagnosticTransports *diag)
119 , _diagnostics(diag) {}
122 _InvokerTask(_InvokerTask &&other) =
default;
123 _InvokerTask(
const _InvokerTask &other) =
delete;
124 _InvokerTask &operator=(
const _InvokerTask &other) =
delete;
126 void operator()()
const {
130 Work_Dispatcher::_TransportDiagnostics(&trap, _diagnostics);
135 _DiagnosticTransports *_diagnostics;
143 struct _MallocTagsInvokerTask {
145 _MallocTagsInvokerTask(Fn &&fn, _DiagnosticTransports *diag)
148 , _mallocTagStack(
TfMallocTag::GetCurrentStackState())
152 _MallocTagsInvokerTask(Fn
const &fn, _DiagnosticTransports *diag)
155 , _mallocTagStack(
TfMallocTag::GetCurrentStackState()) {}
158 _MallocTagsInvokerTask(_MallocTagsInvokerTask &&other) =
default;
159 _MallocTagsInvokerTask(
const _MallocTagsInvokerTask &other) =
delete;
160 _MallocTagsInvokerTask &
161 operator=(
const _MallocTagsInvokerTask &other) =
delete;
163 void operator()()
const {
168 Work_Dispatcher::_TransportDiagnostics(&trap, _diagnostics);
173 _DiagnosticTransports *_diagnostics;
181 _DiagnosticTransports *diagnostics);
185 std::atomic<bool> _isCancelled;
189 _DiagnosticTransports _diagnostics;
192 std::atomic_flag _waitCleanupFlag;
227 :
public Work_Dispatcher<PXR_WORK_IMPL_NS::WorkImpl_Dispatcher>
232struct Work_DeprecatedMutableTask {
233 explicit Work_DeprecatedMutableTask(Fn &&fn)
234 : _fn(
std::move(fn)) {}
236 explicit Work_DeprecatedMutableTask(Fn
const &fn)
240 Work_DeprecatedMutableTask
241 (Work_DeprecatedMutableTask &&other) =
default;
242 Work_DeprecatedMutableTask
243 (
const Work_DeprecatedMutableTask &other) =
delete;
244 Work_DeprecatedMutableTask
245 &operator= (
const Work_DeprecatedMutableTask &other) =
delete;
247 void operator()()
const {
257template <
typename Fn>
258Work_DeprecatedMutableTask<typename std::remove_reference_t<Fn>>
259WorkMakeDeprecatedMutableTask(Fn &&fn) {
260 return Work_DeprecatedMutableTask<typename std::remove_reference_t<Fn>>
261 (std::forward<Fn>(fn));
266PXR_NAMESPACE_CLOSE_SCOPE
A scoped, stack-based mechanism for intercepting and examining diagnostics issued on the current thre...
TF_API bool IsClean() const
Return true if no diagnostics have been captured.
An object that represents a snapshot of a thread's TfMallocTag stack state.
Top-down memory tagging system.
static bool IsInitialized()
Return true if the tagging system is active.
A work dispatcher runs concurrent tasks.