24 #ifndef WORK_ARENA_DISPATCHER_H
25 #define WORK_ARENA_DISPATCHER_H
30 #include "pxr/base/work/dispatcher.h"
31 #include "pxr/base/work/threadLimits.h"
32 #include "pxr/base/work/api.h"
34 #include <tbb/task_arena.h>
37 #include <type_traits>
40 PXR_NAMESPACE_OPEN_SCOPE
79 template <
class Callable,
class A1,
class A2, ...
class AN>
80 void Run(Callable &&c, A1 &&a1, A2 &&a2, ... AN &&aN);
84 template <
class Callable,
class ... Args>
85 inline void Run(Callable &&c, Args&&... args) {
87 _MakeRunner(&_dispatcher,
88 std::bind(std::forward<Callable>(c),
89 std::forward<Args>(args)...)));
104 WORK_API tbb::task_arena *_GetArena()
const;
108 _Runner(
WorkDispatcher *wd, Fn &&fn) : _wd(wd), _fn(std::move(fn)) {}
110 void operator()() { _wd->Run(std::move(_fn)); }
111 void operator()()
const { _wd->Run(std::move(_fn)); }
118 _Runner<typename std::remove_reference<Fn>::type>
120 return _Runner<typename std::remove_reference<Fn>::type>(
121 wd, std::forward<Fn>(fn));
125 tbb::task_arena *_arena;
133 PXR_NAMESPACE_CLOSE_SCOPE
135 #endif // WORK_ARENA_DISPATCHER_H
A work dispatcher runs concurrent tasks.
void Run(Callable &&c, A1 &&a1, A2 &&a2,...AN &&aN)
Add work for the dispatcher to run.
WorkArenaDispatcher()
Constructs a new dispatcher.
WORK_API ~WorkArenaDispatcher()
Wait() for any pending tasks to complete, then destroy the dispatcher.
This is a specialization of the WorkDispatcher that uses an isolated arena to Run() all its tasks in...
WORK_API void Wait()
Block until the work started by Run() completes.
WORK_API void Cancel()
Cancel remaining work and return immediately.