HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
isolatingDispatcher_impl.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_WORK_TBB_ISOLATING_DISPATCHER_IMPL_H
8 #define PXR_BASE_WORK_TBB_ISOLATING_DISPATCHER_IMPL_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/base/work/api.h"
14 
15 #include <tbb/task_arena.h>
16 
17 #include <utility>
18 
19 // TBB implements work stealing, so the impl provides a specialization of the
20 // dispatcher with work stealing isolation semantics:
21 // WorkImpl_IsolatingDispatcher.
22 //
23 // If this is not defined, both WorkDispatcher and WorkIsolatingDispatcher will
24 // use the WorkImpl_Dispatcher implementation.
25 #define WORK_IMPL_HAS_ISOLATING_DISPATCHER
26 
28 
30 {
31 public:
34 
35  WorkImpl_IsolatingDispatcher(WorkImpl_IsolatingDispatcher const &) = delete;
36  WorkImpl_IsolatingDispatcher &operator=(
37  WorkImpl_IsolatingDispatcher const &) = delete;
38 
39  template <class Callable>
40  inline void Run(Callable &&c) {
41  _arena->execute([&dispatcher = _dispatcher, &c](){
42  dispatcher.Run(std::forward<Callable>(c));
43  });
44  }
45 
46  void Reset() {
47  _dispatcher.Reset();
48  }
49 
50  WORK_API void Wait();
51 
52  void Cancel() {
53  _dispatcher.Cancel();
54  }
55 
56 private:
57  tbb::task_arena *_arena;
58  WorkImpl_Dispatcher _dispatcher;
59 };
60 
62 
63 #endif // PXR_BASE_WORK_TBB_ISOLATING_DISPATCHER_IMPL_H
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
WORK_API ~WorkImpl_IsolatingDispatcher()
#define WORK_API
Definition: api.h:23
WorkImpl_IsolatingDispatcher & operator=(WorkImpl_IsolatingDispatcher const &)=delete
WORK_API void Cancel()
WORK_API WorkImpl_IsolatingDispatcher()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
WORK_API void Reset()
Reinitialize context for WorkImpl_Dispatcher if it has one.