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), &_errors));
72 _InvokerTask<
typename std::remove_reference<Callable>::type>(
73 std::forward<Callable>(c), &_errors));
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<TfErrorTransport> _ErrorTransports;
112 struct _InvokerTask {
113 explicit _InvokerTask(Fn &&fn, _ErrorTransports *err)
117 explicit _InvokerTask(Fn
const &fn, _ErrorTransports *err)
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::_TransportErrors(m, _errors);
134 _ErrorTransports *_errors;
142 struct _MallocTagsInvokerTask {
143 explicit _MallocTagsInvokerTask(Fn &&fn, _ErrorTransports *err)
146 , _mallocTagStack(
TfMallocTag::GetCurrentStackState())
149 explicit _MallocTagsInvokerTask(Fn
const &fn, _ErrorTransports *err)
152 , _mallocTagStack(
TfMallocTag::GetCurrentStackState()) {}
155 _MallocTagsInvokerTask(_MallocTagsInvokerTask &&other) =
default;
156 _MallocTagsInvokerTask(
const _MallocTagsInvokerTask &other) =
delete;
157 _MallocTagsInvokerTask &
158 operator=(
const _MallocTagsInvokerTask &other) =
delete;
160 void operator()()
const {
165 Work_Dispatcher::_TransportErrors(m, _errors);
169 _ErrorTransports *_errors;
176 _TransportErrors(
const TfErrorMark &m, _ErrorTransports *errors);
180 std::atomic<bool> _isCancelled;
184 _ErrorTransports _errors;
187 std::atomic_flag _waitCleanupFlag;
222 :
public Work_Dispatcher<PXR_WORK_IMPL_NS::WorkImpl_Dispatcher>
227struct Work_DeprecatedMutableTask {
228 explicit Work_DeprecatedMutableTask(Fn &&fn)
229 : _fn(
std::move(fn)) {}
231 explicit Work_DeprecatedMutableTask(Fn
const &fn)
235 Work_DeprecatedMutableTask
236 (Work_DeprecatedMutableTask &&other) =
default;
237 Work_DeprecatedMutableTask
238 (
const Work_DeprecatedMutableTask &other) =
delete;
239 Work_DeprecatedMutableTask
240 &operator= (
const Work_DeprecatedMutableTask &other) =
delete;
242 void operator()()
const {
252template <
typename Fn>
253Work_DeprecatedMutableTask<typename std::remove_reference_t<Fn>>
254WorkMakeDeprecatedMutableTask(Fn &&fn) {
255 return Work_DeprecatedMutableTask<typename std::remove_reference_t<Fn>>
256 (std::forward<Fn>(fn));
261PXR_NAMESPACE_CLOSE_SCOPE
Class used to record the end of the error-list.
bool IsClean() const
Return true if no new errors were posted in this thread since the last call to SetMark(),...
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.