in benchmarks/pipeline_benchmark.cpp [214:241]
void runTBBPar(std::vector<std::unique_ptr<uint8_t[]>>& results) {
results.resize(kNumImages);
std::atomic<size_t> counter(0);
tbb::parallel_pipeline(
/*max_number_of_live_token=*/std::thread::hardware_concurrency(),
tbb::make_filter<void, Work*>(
tbb::filter::parallel,
[&counter](tbb::flow_control& fc) -> Work* {
size_t curIndex = counter.fetch_add(1, std::memory_order_acquire);
if (curIndex < kNumImages) {
return new Work(fillImage(Work(curIndex)));
}
fc.stop();
return nullptr;
}) &
tbb::make_filter<Work*, Work*>(
tbb::filter::parallel,
[](Work* work) {
*work = computeGeometricMean(std::move(*work));
return work;
}) &
tbb::make_filter<Work*, void>(tbb::filter::parallel, [&results](Work* work) {
size_t index = work->index;
results[index] = tonemap(std::move(*work));
delete work;
}));
}