[PATCH] D87467: [Support] Use unique_function rather than std::function for ThreadPool TaskTy.
Lang Hames via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 10 10:47:21 PDT 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd9c8b0256cfc: [Support] Use unique_function rather than std::function for ThreadPool TaskTy. (authored by lhames).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87467/new/
https://reviews.llvm.org/D87467
Files:
llvm/include/llvm/Support/ThreadPool.h
llvm/unittests/Support/ThreadPool.cpp
Index: llvm/unittests/Support/ThreadPool.cpp
===================================================================
--- llvm/unittests/Support/ThreadPool.cpp
+++ llvm/unittests/Support/ThreadPool.cpp
@@ -133,6 +133,13 @@
ASSERT_EQ(2, i.load());
}
+TEST_F(ThreadPoolTest, NonCopyableTask) {
+ CHECK_UNSUPPORTED();
+ ThreadPool Pool;
+ Pool.async([P = std::make_unique<int>()] {});
+ Pool.wait();
+};
+
TEST_F(ThreadPoolTest, GetFuture) {
CHECK_UNSUPPORTED();
ThreadPool Pool(hardware_concurrency(2));
Index: llvm/include/llvm/Support/ThreadPool.h
===================================================================
--- llvm/include/llvm/Support/ThreadPool.h
+++ llvm/include/llvm/Support/ThreadPool.h
@@ -13,6 +13,7 @@
#ifndef LLVM_SUPPORT_THREAD_POOL_H
#define LLVM_SUPPORT_THREAD_POOL_H
+#include "llvm/ADT/FunctionExtras.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/Threading.h"
#include "llvm/Support/thread.h"
@@ -36,7 +37,7 @@
/// for some work to become available.
class ThreadPool {
public:
- using TaskTy = std::function<void()>;
+ using TaskTy = unique_function<void()>;
using PackagedTaskTy = std::packaged_task<void()>;
/// Construct a pool using the hardware strategy \p S for mapping hardware
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87467.291028.patch
Type: text/x-patch
Size: 1258 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200910/1f573509/attachment.bin>
More information about the llvm-commits
mailing list