From: Teresa Johnson Date: Tue, 15 Dec 2015 04:44:02 +0000 (+0000) Subject: Fix template parameter pack handling in ThreadPool X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=cbfe4141892818d4bcd17558840ce1375ed5bc9d;ds=inline Fix template parameter pack handling in ThreadPool Fixes passing of template parameter pack via std::forward and add unittest. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255617 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Support/ThreadPool.h b/include/llvm/Support/ThreadPool.h index 35dc20867a4..85c062179f0 100644 --- a/include/llvm/Support/ThreadPool.h +++ b/include/llvm/Support/ThreadPool.h @@ -66,7 +66,7 @@ public: template inline std::shared_future async(Function &&F, Args &&... ArgList) { auto Task = - std::bind(std::forward(F), std::forward(ArgList...)); + std::bind(std::forward(F), std::forward(ArgList)...); #ifndef _MSC_VER return asyncImpl(std::move(Task)); #else diff --git a/unittests/Support/ThreadPool.cpp b/unittests/Support/ThreadPool.cpp index d36341e425d..5457cdc1c68 100644 --- a/unittests/Support/ThreadPool.cpp +++ b/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};