22#define _QIO_TBB_FLOW_COMPAT_H
33
44#include < utility>
5- #if __has_include(<tbb/version.h>)
6- #include < tbb/version.h>
7- #elif __has_include(<oneapi/tbb/version.h>)
8- #include < oneapi/tbb/version.h>
9- #endif
105#include < tbb/flow_graph.h>
116
7+ // TBB 2019 exposes only <tbb/flow_graph.h> and uses source_node/decrement.
8+ // oneTBB ships its canonical flow-graph API under <oneapi/tbb/flow_graph.h>
9+ // and uses input_node/decrementer(). Probe that header layout instead of
10+ // version macros: some wrapper headers do not surface TBB_INTERFACE_VERSION,
11+ // and mixing version headers from different packages can mis-detect the actual
12+ // flow-graph API in use. Callers can override this probe if they know better.
13+ #ifndef QIO_TBB_FLOW_USES_INPUT_NODE
14+ #if defined(__has_include)
15+ #if __has_include(<oneapi/tbb/flow_graph.h>)
16+ #define QIO_TBB_FLOW_USES_INPUT_NODE 1
17+ #else
18+ #define QIO_TBB_FLOW_USES_INPUT_NODE 0
19+ #endif
20+ #else
21+ #define QIO_TBB_FLOW_USES_INPUT_NODE 0
22+ #endif
23+ #endif
24+
1225namespace qio {
1326namespace tbb_compat {
1427
15- // Normalize old TBB flow-graph source APIs across versions.
28+ // Normalize the flow-graph API split between classic TBB (interface 11)
29+ // and oneTBB (interface 12+).
1630//
17- // Old interface :
31+ // Classic TBB :
1832// tbb::flow::source_node<T>
33+ // limiter_node.decrement
1934// body signature: bool(T & out)
2035//
21- // Newer interface :
36+ // oneTBB :
2237// tbb::flow::input_node<T>
38+ // limiter_node.decrementer()
2339// body signature: T(tbb::flow_control & fc)
2440//
2541// Normalized contract used below:
2642// bool(T & out)
2743//
2844// Return true and fill `out` to emit one message.
2945// Return false to stop the node.
30- #if defined(TBB_INTERFACE_VERSION) && TBB_INTERFACE_VERSION >= 11102
46+ #if QIO_TBB_FLOW_USES_INPUT_NODE
3147template <class T >
3248struct source_node : tbb::flow::input_node<T> {
3349 using base_type = tbb::flow::input_node<T>;
@@ -43,6 +59,11 @@ struct source_node : tbb::flow::input_node<T> {
4359 return out;
4460 }) {}
4561};
62+
63+ template <class LimiterNode >
64+ inline auto & decrementer (LimiterNode & node) {
65+ return node.decrementer ();
66+ }
4667#else
4768template <class T >
4869struct source_node : tbb::flow::source_node<T> {
@@ -52,6 +73,11 @@ struct source_node : tbb::flow::source_node<T> {
5273 source_node (tbb::flow::graph & graph, Body && body) :
5374 base_type (graph, std::forward<Body>(body), false ) {}
5475};
76+
77+ template <class LimiterNode >
78+ inline auto & decrementer (LimiterNode & node) {
79+ return node.decrement ;
80+ }
5581#endif
5682
5783} // namespace tbb_compat
0 commit comments