Skip to content

Commit

Permalink
Fix template parameter pack handling in ThreadPool
Browse files Browse the repository at this point in the history
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
  • Loading branch information
teresajohnson committed Dec 15, 2015
1 parent db01e41 commit cbfe414
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/llvm/Support/ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ThreadPool {
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
Expand Down
14 changes: 14 additions & 0 deletions unittests/Support/ThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit cbfe414

Please sign in to comment.