Skip to content

Commit 0ff9917

Browse files
committed
fix tbb compat
1 parent 485c90d commit 0ff9917

2 files changed

Lines changed: 36 additions & 10 deletions

File tree

include/io/multithreaded_block_module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ struct BlockCompressReaderMT {
314314
OrderedBlock block;
315315
while( true ) {
316316
if( sequencer_node.try_get(block) ) {
317-
decompressor_limiter_node.decrementer().try_put(tbb::flow::continue_msg{});
317+
qio::tbb_compat::decrementer(decompressor_limiter_node).try_put(tbb::flow::continue_msg{});
318318
available_blocks.push(current_block);
319319
current_block = block.block;
320320
current_blocksize = block.blocksize;

include/io/tbb_flow_compat.h

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,48 @@
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+
1225
namespace qio {
1326
namespace 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
3147
template <class T>
3248
struct 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
4768
template <class T>
4869
struct 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

Comments
 (0)