diff options
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/include/llvm/Support/ThreadPool.h | 2 | ||||
-rw-r--r-- | llvm/unittests/Support/ThreadPool.cpp | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/llvm/include/llvm/Support/ThreadPool.h b/llvm/include/llvm/Support/ThreadPool.h index 35dc20867a4..85c062179f0 100644 --- a/llvm/include/llvm/Support/ThreadPool.h +++ b/llvm/include/llvm/Support/ThreadPool.h @@ -66,7 +66,7 @@ public: template <typename Function, typename... Args> inline std::shared_future<VoidTy> async(Function &&F, Args &&... ArgList) { auto Task = - std::bind(std::forward<Function>(F), std::forward<Args...>(ArgList...)); + std::bind(std::forward<Function>(F), std::forward<Args>(ArgList)...); #ifndef _MSC_VER return asyncImpl(std::move(Task)); #else diff --git a/llvm/unittests/Support/ThreadPool.cpp b/llvm/unittests/Support/ThreadPool.cpp index d36341e425d..5457cdc1c68 100644 --- a/llvm/unittests/Support/ThreadPool.cpp +++ b/llvm/unittests/Support/ThreadPool.cpp @@ -44,6 +44,20 @@ TEST(ThreadPoolTest, AsyncBarrier) { ASSERT_EQ(5, checked_in); } +static void TestFunc(std::atomic_int &checked_in, int i) { checked_in += i; } + +TEST(ThreadPoolTest, AsyncBarrierArgs) { + // Test that async works with a function requiring multiple parameters. + std::atomic_int checked_in{0}; + + ThreadPool Pool; + for (size_t i = 0; i < 5; ++i) { + Pool.async(TestFunc, std::ref(checked_in), i); + } + Pool.wait(); + ASSERT_EQ(10, checked_in); +} + TEST(ThreadPoolTest, Async) { ThreadPool Pool; std::atomic_int i{0}; |