dispenso 1.6.0
A library for task parallelism
Loading...
Searching...
No Matches
parallel_invoke.h
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
10#include <utility>
11
12#include <dispenso/platform.h>
13#include <dispenso/task_set.h>
14
15namespace dispenso {
16
41template <typename F>
42DISPENSO_INLINE void parallel_invoke(ConcurrentTaskSet& /*tasks*/, F&& f) {
43 // Single-functor base case: run inline.
44 std::forward<F>(f)();
45}
46
47template <typename F1, typename F2, typename... Fs>
48DISPENSO_INLINE void parallel_invoke(ConcurrentTaskSet& tasks, F1&& f1, F2&& f2, Fs&&... fs) {
49 // skipRecheck=true: the per-call inline gate's TaskSet check is enough; the
50 // pool-level recheck is redundant when the caller is in a fork-join
51 // pattern.
52 tasks.schedule(std::forward<F1>(f1), /*skipRecheck=*/true);
53 parallel_invoke(tasks, std::forward<F2>(f2), std::forward<Fs>(fs)...);
54}
55
56} // namespace dispenso