diff options
author | Zachary Turner <zturner@google.com> | 2018-06-13 21:24:19 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2018-06-13 21:24:19 +0000 |
commit | 9b8b0794b8dd8ebdd17b3653ad29abcc6b7a3583 (patch) | |
tree | d6094f4278eaefe72b341aca015c3b9ba185dec0 /llvm/lib/Support/ThreadPool.cpp | |
parent | 03185797d73e2c28ae37195ea24a4f0a7e290914 (diff) | |
download | bcm5719-llvm-9b8b0794b8dd8ebdd17b3653ad29abcc6b7a3583.tar.gz bcm5719-llvm-9b8b0794b8dd8ebdd17b3653ad29abcc6b7a3583.zip |
Revert "Enable ThreadPool to queue tasks that return values."
This is failing to compile when LLVM_ENABLE_THREADS is false,
and the fix is not immediately obvious, so reverting while I look
into it.
llvm-svn: 334658
Diffstat (limited to 'llvm/lib/Support/ThreadPool.cpp')
-rw-r--r-- | llvm/lib/Support/ThreadPool.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/llvm/lib/Support/ThreadPool.cpp b/llvm/lib/Support/ThreadPool.cpp index fef665ba3d1..d0212ca1346 100644 --- a/llvm/lib/Support/ThreadPool.cpp +++ b/llvm/lib/Support/ThreadPool.cpp @@ -32,7 +32,7 @@ ThreadPool::ThreadPool(unsigned ThreadCount) for (unsigned ThreadID = 0; ThreadID < ThreadCount; ++ThreadID) { Threads.emplace_back([&] { while (true) { - std::unique_ptr<TaskBase> Task; + PackagedTaskTy Task; { std::unique_lock<std::mutex> LockGuard(QueueLock); // Wait for tasks to be pushed in the queue @@ -54,7 +54,7 @@ ThreadPool::ThreadPool(unsigned ThreadCount) Tasks.pop(); } // Run the task we just grabbed - Task->execute(); + Task(); { // Adjust `ActiveThreads`, in case someone waits on ThreadPool::wait() @@ -79,6 +79,23 @@ void ThreadPool::wait() { [&] { return !ActiveThreads && Tasks.empty(); }); } +std::shared_future<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(); + { + // Lock the queue and push the new task + std::unique_lock<std::mutex> LockGuard(QueueLock); + + // Don't allow enqueueing after disabling the pool + assert(EnableFlag && "Queuing a thread during ThreadPool destruction"); + + Tasks.push(std::move(PackagedTask)); + } + QueueCondition.notify_one(); + return Future.share(); +} + // The destructor joins all threads, waiting for completion. ThreadPool::~ThreadPool() { { |