Add ctor to CPUThreadPoolExecutor to enable custom queue sizes
authorMatt Dordal <mnd@fb.com>
Fri, 13 Mar 2015 17:44:08 +0000 (10:44 -0700)
committerAndre Azevedo <aap@fb.com>
Wed, 18 Mar 2015 03:18:45 +0000 (20:18 -0700)
Summary:
Seems useful to do without passing in a totally custom queue. Makes
the client code a bit simpler.

Test Plan: used it, saw low memory usage and no crash

Reviewed By: davejwatson@fb.com

Subscribers: trunkagent, iaroslav, fugalh, folly-diffs@, jsedgwick, yfeldblum, slarsen

FB internal diff: D1907874

Signature: t1:1907874:1426268010:3159ae339b51f5dbc7fe034644bbc968b92b072c

folly/wangle/concurrent/CPUThreadPoolExecutor.cpp
folly/wangle/concurrent/CPUThreadPoolExecutor.h

index 25b2214842b44d7e1dbd45fbb87b16bc62bc8323..fcc835cda400b136d2c32517d62ec7374f113796 100644 (file)
@@ -57,6 +57,18 @@ CPUThreadPoolExecutor::CPUThreadPoolExecutor(
               CPUThreadPoolExecutor::kDefaultMaxQueueSize),
           std::move(threadFactory)) {}
 
+CPUThreadPoolExecutor::CPUThreadPoolExecutor(
+    size_t numThreads,
+    uint32_t numPriorities,
+    size_t maxQueueSize,
+    std::shared_ptr<ThreadFactory> threadFactory)
+    : CPUThreadPoolExecutor(
+          numThreads,
+          folly::make_unique<PriorityLifoSemMPMCQueue<CPUTask>>(
+              numPriorities,
+              maxQueueSize),
+          std::move(threadFactory)) {}
+
 CPUThreadPoolExecutor::~CPUThreadPoolExecutor() {
   stop();
   CHECK(threadsToStop_ == 0);
index bd37d324d2343bc9671e95d0fc2d2d932735efea..56833e22abd97d7fd8ee28f20e4b4425106a5096 100644 (file)
@@ -42,6 +42,13 @@ class CPUThreadPoolExecutor : public ThreadPoolExecutor {
       std::shared_ptr<ThreadFactory> threadFactory =
           std::make_shared<NamedThreadFactory>("CPUThreadPool"));
 
+  explicit CPUThreadPoolExecutor(
+      size_t numThreads,
+      uint32_t numPriorities,
+      size_t maxQueueSize,
+      std::shared_ptr<ThreadFactory> threadFactory =
+          std::make_shared<NamedThreadFactory>("CPUThreadPool"));
+
   ~CPUThreadPoolExecutor();
 
   void add(Func func) override;