[llvm] r255617 - Fix template parameter pack handling in ThreadPool
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 14 20:44:07 PST 2015
Author: tejohnson
Date: Mon Dec 14 22:44:02 2015
New Revision: 255617
URL: http://llvm.org/viewvc/llvm-project?rev=255617&view=rev
Log:
Fix template parameter pack handling in ThreadPool
Fixes passing of template parameter pack via std::forward and add
unittest.
Modified:
llvm/trunk/include/llvm/Support/ThreadPool.h
llvm/trunk/unittests/Support/ThreadPool.cpp
Modified: llvm/trunk/include/llvm/Support/ThreadPool.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ThreadPool.h?rev=255617&r1=255616&r2=255617&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ThreadPool.h (original)
+++ llvm/trunk/include/llvm/Support/ThreadPool.h Mon Dec 14 22:44:02 2015
@@ -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
Modified: llvm/trunk/unittests/Support/ThreadPool.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ThreadPool.cpp?rev=255617&r1=255616&r2=255617&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/ThreadPool.cpp (original)
+++ llvm/trunk/unittests/Support/ThreadPool.cpp Mon Dec 14 22:44:02 2015
@@ -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};
More information about the llvm-commits
mailing list