7#ifndef PXR_BASE_WORK_TBB_TASK_GRAPH_IMPL_H
8#define PXR_BASE_WORK_TBB_TASK_GRAPH_IMPL_H
11#include "pxr/base/work/api.h"
15#if __has_include(<tbb/tbb_stddef.h>)
16#include <tbb/tbb_stddef.h>
17#elif __has_include(<tbb/version.h>)
18#include <tbb/version.h>
21#ifndef TBB_INTERFACE_VERSION_MAJOR
22#error "TBB version macro TBB_INTERFACE_VERSION_MAJOR not found"
25#if TBB_INTERFACE_VERSION_MAJOR < 12
31#define WORK_IMPL_HAS_TASK_GRAPH
35PXR_NAMESPACE_OPEN_SCOPE
37class WorkImpl_TaskGraph
40 WORK_API WorkImpl_TaskGraph();
41 WORK_API ~WorkImpl_TaskGraph() noexcept;
43 WorkImpl_TaskGraph(WorkImpl_TaskGraph const &) = delete;
44 WorkImpl_TaskGraph &operator=(WorkImpl_TaskGraph const &) = delete;
48 template <typename F, typename ... Args>
49 F * AllocateTask(Args&&... args);
52 inline
void RunTask(F * task) {
53 tbb::task::spawn(*task);
60 tbb::task_group_context _context;
64 tbb::empty_task *_rootTask;
67class WorkImpl_TaskGraph::BaseTask :
public tbb::task {
70 WORK_API
virtual ~BaseTask();
72 void AddChildReference() {
73 increment_ref_count();
76 int RemoveChildReference() {
77 return decrement_ref_count();
80 template <
typename F,
typename... Args>
81 F * AllocateChild(Args &&...args) {
82 return new (tbb::task::allocate_additional_child_of(*
this))
83 F{std::forward<Args>(args)...};
87 void _RecycleAsContinuation() {
88 recycle_as_safe_continuation();
93template <
typename F,
typename ... Args>
94F * WorkImpl_TaskGraph::AllocateTask(Args&&... args) {
95 return new (tbb::task::allocate_additional_child_of(*_rootTask))
96 F{std::forward<Args>(args)...};
99PXR_NAMESPACE_CLOSE_SCOPE