Commit edbdc3d4 authored by James Sedgwick's avatar James Sedgwick Committed by Andrii Grynenko

in thread pools, take factory as shared ptr

Summary: needed for thrift server. if you have some sort of stateful/functional factory and you want to hold on to it, you should be allowed to

Test Plan: compiles with forthcoming thrift diff

Reviewed By: davejwatson@fb.com

Subscribers: trunkagent, fugalh, njormrod

FB internal diff: D1584587
parent ca5fc366
...@@ -23,7 +23,7 @@ const size_t CPUThreadPoolExecutor::kDefaultMaxQueueSize = 1 << 18; ...@@ -23,7 +23,7 @@ const size_t CPUThreadPoolExecutor::kDefaultMaxQueueSize = 1 << 18;
CPUThreadPoolExecutor::CPUThreadPoolExecutor( CPUThreadPoolExecutor::CPUThreadPoolExecutor(
size_t numThreads, size_t numThreads,
std::unique_ptr<BlockingQueue<CPUTask>> taskQueue, std::unique_ptr<BlockingQueue<CPUTask>> taskQueue,
std::unique_ptr<ThreadFactory> threadFactory) std::shared_ptr<ThreadFactory> threadFactory)
: ThreadPoolExecutor(numThreads, std::move(threadFactory)), : ThreadPoolExecutor(numThreads, std::move(threadFactory)),
taskQueue_(std::move(taskQueue)) { taskQueue_(std::move(taskQueue)) {
addThreads(numThreads); addThreads(numThreads);
......
...@@ -28,8 +28,8 @@ class CPUThreadPoolExecutor : public ThreadPoolExecutor { ...@@ -28,8 +28,8 @@ class CPUThreadPoolExecutor : public ThreadPoolExecutor {
std::unique_ptr<BlockingQueue<CPUTask>> taskQueue = std::unique_ptr<BlockingQueue<CPUTask>> taskQueue =
folly::make_unique<LifoSemMPMCQueue<CPUTask>>( folly::make_unique<LifoSemMPMCQueue<CPUTask>>(
CPUThreadPoolExecutor::kDefaultMaxQueueSize), CPUThreadPoolExecutor::kDefaultMaxQueueSize),
std::unique_ptr<ThreadFactory> threadFactory = std::shared_ptr<ThreadFactory> threadFactory =
folly::make_unique<NamedThreadFactory>("CPUThreadPool")); std::make_shared<NamedThreadFactory>("CPUThreadPool"));
~CPUThreadPoolExecutor(); ~CPUThreadPoolExecutor();
......
...@@ -24,7 +24,7 @@ namespace folly { namespace wangle { ...@@ -24,7 +24,7 @@ namespace folly { namespace wangle {
IOThreadPoolExecutor::IOThreadPoolExecutor( IOThreadPoolExecutor::IOThreadPoolExecutor(
size_t numThreads, size_t numThreads,
std::unique_ptr<ThreadFactory> threadFactory) std::shared_ptr<ThreadFactory> threadFactory)
: ThreadPoolExecutor(numThreads, std::move(threadFactory)), : ThreadPoolExecutor(numThreads, std::move(threadFactory)),
nextThread_(0) { nextThread_(0) {
addThreads(numThreads); addThreads(numThreads);
......
...@@ -24,8 +24,8 @@ class IOThreadPoolExecutor : public ThreadPoolExecutor { ...@@ -24,8 +24,8 @@ class IOThreadPoolExecutor : public ThreadPoolExecutor {
public: public:
explicit IOThreadPoolExecutor( explicit IOThreadPoolExecutor(
size_t numThreads, size_t numThreads,
std::unique_ptr<ThreadFactory> threadFactory = std::shared_ptr<ThreadFactory> threadFactory =
folly::make_unique<NamedThreadFactory>("IOThreadPool")); std::make_shared<NamedThreadFactory>("IOThreadPool"));
~IOThreadPoolExecutor(); ~IOThreadPoolExecutor();
......
...@@ -20,7 +20,7 @@ namespace folly { namespace wangle { ...@@ -20,7 +20,7 @@ namespace folly { namespace wangle {
ThreadPoolExecutor::ThreadPoolExecutor( ThreadPoolExecutor::ThreadPoolExecutor(
size_t numThreads, size_t numThreads,
std::unique_ptr<ThreadFactory> threadFactory) std::shared_ptr<ThreadFactory> threadFactory)
: threadFactory_(std::move(threadFactory)) {} : threadFactory_(std::move(threadFactory)) {}
ThreadPoolExecutor::~ThreadPoolExecutor() { ThreadPoolExecutor::~ThreadPoolExecutor() {
......
...@@ -35,7 +35,7 @@ class ThreadPoolExecutor : public experimental::Executor { ...@@ -35,7 +35,7 @@ class ThreadPoolExecutor : public experimental::Executor {
public: public:
explicit ThreadPoolExecutor( explicit ThreadPoolExecutor(
size_t numThreads, size_t numThreads,
std::unique_ptr<ThreadFactory> threadFactory); std::shared_ptr<ThreadFactory> threadFactory);
~ThreadPoolExecutor(); ~ThreadPoolExecutor();
...@@ -157,7 +157,7 @@ class ThreadPoolExecutor : public experimental::Executor { ...@@ -157,7 +157,7 @@ class ThreadPoolExecutor : public experimental::Executor {
std::queue<ThreadPtr> queue_; std::queue<ThreadPtr> queue_;
}; };
std::unique_ptr<ThreadFactory> threadFactory_; std::shared_ptr<ThreadFactory> threadFactory_;
ThreadList threadList_; ThreadList threadList_;
RWSpinLock threadListLock_; RWSpinLock threadListLock_;
StoppedThreadQueue stoppedThreads_; StoppedThreadQueue stoppedThreads_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment