24 #ifndef PXR_BASE_WORK_DISPATCHER_H
25 #define PXR_BASE_WORK_DISPATCHER_H
36 #include <tbb/concurrent_vector.h>
40 #include <type_traits>
85 WorkDispatcher &
operator=(WorkDispatcher
const &) =
delete;
99 template <
class Callable,
class A1,
class A2, ...
class AN>
100 void Run(Callable &&
c, A1 &&a1, A2 &&a2, ... AN &&aN);
104 template <
class Callable>
105 inline void Run(Callable &&
c) {
106 _rootTask->spawn(_MakeInvokerTask(std::forward<Callable>(
c)));
109 template <
class Callable,
class A0,
class ... Args>
110 inline void Run(Callable &&
c, A0 &&a0, Args&&...
args) {
111 Run(std::bind(std::forward<Callable>(
c),
112 std::forward<A0>(a0),
113 std::forward<Args>(
args)...));
134 typedef tbb::concurrent_vector<TfErrorTransport> _ErrorTransports;
140 struct _InvokerTask :
public tbb::task {
141 explicit _InvokerTask(Fn &&fn, _ErrorTransports *err)
142 : _fn(std::move(fn)), _errors(err) {}
144 explicit _InvokerTask(Fn
const &fn, _ErrorTransports *err)
145 : _fn(fn), _errors(err) {}
147 virtual tbb::task* execute() {
151 WorkDispatcher::_TransportErrors(m, _errors);
156 _ErrorTransports *_errors;
162 _MakeInvokerTask(Fn &&fn) {
163 return *
new( _rootTask->allocate_additional_child_of(*_rootTask) )
165 std::forward<Fn>(fn), &_errors);
171 _TransportErrors(
const TfErrorMark &m, _ErrorTransports *errors);
175 tbb::task_group_context _context;
176 tbb::empty_task* _rootTask;
180 _ErrorTransports _errors;
183 std::atomic_flag _waitCleanupFlag;
190 #endif // PXR_BASE_WORK_DISPATCHER_H
void Run(Callable &&c, A0 &&a0, Args &&...args)
WorkDispatcher & operator=(WorkDispatcher const &)=delete
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
WORK_API WorkDispatcher()
Construct a new dispatcher.
#define PXR_NAMESPACE_CLOSE_SCOPE
**If you just want to fire and args
WORK_API ~WorkDispatcher()
Wait() for any pending tasks to complete, then destroy the dispatcher.
WORK_API void Wait()
Block until the work started by Run() completes.