Loading...
Searching...
No Matches
isolatingDispatcher_impl.h
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"
13#include "pxr/base/work/workTBB/dispatcher_impl.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
27PXR_NAMESPACE_OPEN_SCOPE
28
29class WorkImpl_IsolatingDispatcher
30{
31public:
32 WORK_API WorkImpl_IsolatingDispatcher();
33 WORK_API ~WorkImpl_IsolatingDispatcher();
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
56private:
57 tbb::task_arena *_arena;
58 WorkImpl_Dispatcher _dispatcher;
59};
60
61PXR_NAMESPACE_CLOSE_SCOPE
62
63#endif // PXR_BASE_WORK_TBB_ISOLATING_DISPATCHER_IMPL_H