[llvm] r288016 - [ThreadPool] Simplify the interface. NFCI.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 28 00:53:44 PST 2016
Author: davide
Date: Mon Nov 28 02:53:41 2016
New Revision: 288016
URL: http://llvm.org/viewvc/llvm-project?rev=288016&view=rev
Log:
[ThreadPool] Simplify the interface. NFCI.
The callers don't use the return value. Found by Michael
Spencer.
Modified:
llvm/trunk/include/llvm/Support/ThreadPool.h
llvm/trunk/lib/Support/ThreadPool.cpp
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=288016&r1=288015&r2=288016&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ThreadPool.h (original)
+++ llvm/trunk/include/llvm/Support/ThreadPool.h Mon Nov 28 02:53:41 2016
@@ -75,29 +75,26 @@ public:
/// Asynchronous submission of a task to the pool. The returned future can be
/// used to wait for the task to finish and is *non-blocking* on destruction.
template <typename Function, typename... Args>
- inline std::shared_future<VoidTy> async(Function &&F, Args &&... ArgList) {
+ inline void async(Function &&F, Args &&... ArgList) {
auto Task =
std::bind(std::forward<Function>(F), std::forward<Args>(ArgList)...);
#ifndef _MSC_VER
- return asyncImpl(std::move(Task));
+ asyncImpl(std::move(Task));
#else
// This lambda has to be marked mutable because MSVC 2013's std::bind call
// operator isn't const qualified.
- return asyncImpl([Task](VoidTy) mutable -> VoidTy {
- Task();
- return VoidTy();
- });
+ asyncImpl([Task](VoidTy) mutable { Task(); });
#endif
}
/// Asynchronous submission of a task to the pool. The returned future can be
/// used to wait for the task to finish and is *non-blocking* on destruction.
template <typename Function>
- inline std::shared_future<VoidTy> async(Function &&F) {
+ inline void async(Function &&F) {
#ifndef _MSC_VER
- return asyncImpl(std::forward<Function>(F));
+ asyncImpl(std::forward<Function>(F));
#else
- return asyncImpl([F] (VoidTy) -> VoidTy { F(); return VoidTy(); });
+ asyncImpl([F] (VoidTy) { F(); });
#endif
}
@@ -106,9 +103,8 @@ public:
void wait();
private:
- /// Asynchronous submission of a task to the pool. The returned future can be
- /// used to wait for the task to finish and is *non-blocking* on destruction.
- std::shared_future<VoidTy> asyncImpl(TaskTy F);
+ /// Asynchronous submission of a task to the pool.
+ void asyncImpl(TaskTy F);
/// Threads in flight
std::vector<llvm::thread> Threads;
Modified: llvm/trunk/lib/Support/ThreadPool.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ThreadPool.cpp?rev=288016&r1=288015&r2=288016&view=diff
==============================================================================
--- llvm/trunk/lib/Support/ThreadPool.cpp (original)
+++ llvm/trunk/lib/Support/ThreadPool.cpp Mon Nov 28 02:53:41 2016
@@ -82,7 +82,7 @@ void ThreadPool::wait() {
[&] { return !ActiveThreads && Tasks.empty(); });
}
-std::shared_future<ThreadPool::VoidTy> ThreadPool::asyncImpl(TaskTy Task) {
+void ThreadPool::asyncImpl(TaskTy Task) {
/// Wrap the Task in a packaged_task to return a future object.
PackagedTaskTy PackagedTask(std::move(Task));
auto Future = PackagedTask.get_future();
@@ -96,7 +96,6 @@ std::shared_future<ThreadPool::VoidTy> T
Tasks.push(std::move(PackagedTask));
}
QueueCondition.notify_one();
- return Future.share();
}
// The destructor joins all threads, waiting for completion.
@@ -136,7 +135,7 @@ void ThreadPool::wait() {
}
}
-std::shared_future<ThreadPool::VoidTy> ThreadPool::asyncImpl(TaskTy Task) {
+void ThreadPool::asyncImpl(TaskTy Task) {
#ifndef _MSC_VER
// Get a Future with launch::deferred execution using std::async
auto Future = std::async(std::launch::deferred, std::move(Task)).share();
@@ -148,7 +147,6 @@ std::shared_future<ThreadPool::VoidTy> T
PackagedTaskTy PackagedTask([Future](bool) -> bool { Future.get(); return false; });
#endif
Tasks.push(std::move(PackagedTask));
- return Future;
}
ThreadPool::~ThreadPool() {
Modified: llvm/trunk/unittests/Support/ThreadPool.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ThreadPool.cpp?rev=288016&r1=288015&r2=288016&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/ThreadPool.cpp (original)
+++ llvm/trunk/unittests/Support/ThreadPool.cpp Mon Nov 28 02:53:41 2016
@@ -131,22 +131,6 @@ TEST_F(ThreadPoolTest, Async) {
ASSERT_EQ(2, i.load());
}
-TEST_F(ThreadPoolTest, GetFuture) {
- CHECK_UNSUPPORTED();
- ThreadPool Pool{2};
- std::atomic_int i{0};
- Pool.async([this, &i] {
- waitForMainThread();
- ++i;
- });
- // Force the future using get()
- Pool.async([&i] { ++i; }).get();
- ASSERT_NE(2, i.load());
- setMainThreadReady();
- Pool.wait();
- ASSERT_EQ(2, i.load());
-}
-
TEST_F(ThreadPoolTest, PoolDestruction) {
CHECK_UNSUPPORTED();
// Test that we are waiting on destruction
More information about the llvm-commits
mailing list