diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2021-12-02 21:49:08 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2022-06-04 11:59:04 +0000 |
commit | 574b7079b96703a748f89ef5adb7dc3e26b8f7fc (patch) | |
tree | 195000196b1e0cc13dea43258fa240e006f48184 /contrib/llvm-project/llvm/lib/Support/ThreadPool.cpp | |
parent | 1f6fd64fe9c996b4795ee4a6c66b8f9216747560 (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/ThreadPool.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Support/ThreadPool.cpp | 29 |
1 files changed, 1 insertions, 28 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/ThreadPool.cpp b/contrib/llvm-project/llvm/lib/Support/ThreadPool.cpp index 81926d8071b2..c11e16d3cf98 100644 --- a/contrib/llvm-project/llvm/lib/Support/ThreadPool.cpp +++ b/contrib/llvm-project/llvm/lib/Support/ThreadPool.cpp @@ -29,7 +29,7 @@ ThreadPool::ThreadPool(ThreadPoolStrategy S) Threads.emplace_back([S, ThreadID, this] { S.apply_thread_strategy(ThreadID); while (true) { - PackagedTaskTy Task; + std::function<void()> Task; { std::unique_lock<std::mutex> LockGuard(QueueLock); // Wait for tasks to be pushed in the queue @@ -80,23 +80,6 @@ bool ThreadPool::isWorkerThread() const { return false; } -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() { { @@ -128,16 +111,6 @@ void ThreadPool::wait() { } } -std::shared_future<void> ThreadPool::asyncImpl(TaskTy Task) { - // Get a Future with launch::deferred execution using std::async - auto Future = std::async(std::launch::deferred, std::move(Task)).share(); - // Wrap the future so that both ThreadPool::wait() can operate and the - // returned future can be sync'ed on. - PackagedTaskTy PackagedTask([Future]() { Future.get(); }); - Tasks.push(std::move(PackagedTask)); - return Future; -} - ThreadPool::~ThreadPool() { wait(); } #endif |