in thread pools, take factory as shared ptr
authorJames Sedgwick <jsedgwick@fb.com>
Wed, 1 Oct 2014 17:55:34 +0000 (10:55 -0700)
committerAndrii Grynenko <andrii@fb.com>
Wed, 15 Oct 2014 00:47:09 +0000 (17:47 -0700)
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

folly/experimental/wangle/concurrent/CPUThreadPoolExecutor.cpp
folly/experimental/wangle/concurrent/CPUThreadPoolExecutor.h
folly/experimental/wangle/concurrent/IOThreadPoolExecutor.cpp
folly/experimental/wangle/concurrent/IOThreadPoolExecutor.h
folly/experimental/wangle/concurrent/ThreadPoolExecutor.cpp
folly/experimental/wangle/concurrent/ThreadPoolExecutor.h

index 6d826b55ed81a287fa149304816cbad71dc5c9ff..715bd3722cbe10fa25831f1bd14344dc539d8c35 100644 (file)
@@ -23,7 +23,7 @@ const size_t CPUThreadPoolExecutor::kDefaultMaxQueueSize = 1 << 18;
 CPUThreadPoolExecutor::CPUThreadPoolExecutor(
     size_t numThreads,
     std::unique_ptr<BlockingQueue<CPUTask>> taskQueue,
-    std::unique_ptr<ThreadFactory> threadFactory)
+    std::shared_ptr<ThreadFactory> threadFactory)
     : ThreadPoolExecutor(numThreads, std::move(threadFactory)),
       taskQueue_(std::move(taskQueue)) {
   addThreads(numThreads);
index 28e2dad6e85b9b0850ed9dcf43254962d702a49c..f331232f4b9df6a88a3b9aa8d6d884da3ea91764 100644 (file)
@@ -28,8 +28,8 @@ class CPUThreadPoolExecutor : public ThreadPoolExecutor {
       std::unique_ptr<BlockingQueue<CPUTask>> taskQueue =
           folly::make_unique<LifoSemMPMCQueue<CPUTask>>(
               CPUThreadPoolExecutor::kDefaultMaxQueueSize),
-      std::unique_ptr<ThreadFactory> threadFactory =
-          folly::make_unique<NamedThreadFactory>("CPUThreadPool"));
+      std::shared_ptr<ThreadFactory> threadFactory =
+          std::make_shared<NamedThreadFactory>("CPUThreadPool"));
 
   ~CPUThreadPoolExecutor();
 
index 8de3d5ab1501d1a1bdd62456991871dae798db85..a58b3f44358e78585e80afa1675fac512eaaeb65 100644 (file)
@@ -24,7 +24,7 @@ namespace folly { namespace wangle {
 
 IOThreadPoolExecutor::IOThreadPoolExecutor(
     size_t numThreads,
-    std::unique_ptr<ThreadFactory> threadFactory)
+    std::shared_ptr<ThreadFactory> threadFactory)
   : ThreadPoolExecutor(numThreads, std::move(threadFactory)),
     nextThread_(0) {
   addThreads(numThreads);
index a6bf5215ff0b140c2e4801c8098bf7723dfd1ecc..7acaafe80e87956ec9941c5e19cc878e5b8a3728 100644 (file)
@@ -24,8 +24,8 @@ class IOThreadPoolExecutor : public ThreadPoolExecutor {
  public:
   explicit IOThreadPoolExecutor(
       size_t numThreads,
-      std::unique_ptr<ThreadFactory> threadFactory =
-          folly::make_unique<NamedThreadFactory>("IOThreadPool"));
+      std::shared_ptr<ThreadFactory> threadFactory =
+          std::make_shared<NamedThreadFactory>("IOThreadPool"));
 
   ~IOThreadPoolExecutor();
 
index d8ddfac15e4c419e9904fa62bd88f43ee4bb808e..5924f736051b70ab4ccc815fd0101281970495fe 100644 (file)
@@ -20,7 +20,7 @@ namespace folly { namespace wangle {
 
 ThreadPoolExecutor::ThreadPoolExecutor(
     size_t numThreads,
-    std::unique_ptr<ThreadFactory> threadFactory)
+    std::shared_ptr<ThreadFactory> threadFactory)
     : threadFactory_(std::move(threadFactory)) {}
 
 ThreadPoolExecutor::~ThreadPoolExecutor() {
index 54819ad6080ff35ce58da6dd4add7d0dd9cfd656..7cbbb3215ea6aa97959a2922c6675c35c7779b36 100644 (file)
@@ -35,7 +35,7 @@ class ThreadPoolExecutor : public experimental::Executor {
  public:
   explicit ThreadPoolExecutor(
       size_t numThreads,
-      std::unique_ptr<ThreadFactory> threadFactory);
+      std::shared_ptr<ThreadFactory> threadFactory);
 
   ~ThreadPoolExecutor();
 
@@ -157,7 +157,7 @@ class ThreadPoolExecutor : public experimental::Executor {
     std::queue<ThreadPtr> queue_;
   };
 
-  std::unique_ptr<ThreadFactory> threadFactory_;
+  std::shared_ptr<ThreadFactory> threadFactory_;
   ThreadList threadList_;
   RWSpinLock threadListLock_;
   StoppedThreadQueue stoppedThreads_;