From aae7c5b3cd843fcd57cedf2558204c7c994353e8 Mon Sep 17 00:00:00 2001 From: Matt Dordal Date: Fri, 13 Mar 2015 10:44:08 -0700 Subject: [PATCH] Add ctor to CPUThreadPoolExecutor to enable custom queue sizes 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 | 12 ++++++++++++ folly/wangle/concurrent/CPUThreadPoolExecutor.h | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/folly/wangle/concurrent/CPUThreadPoolExecutor.cpp b/folly/wangle/concurrent/CPUThreadPoolExecutor.cpp index 25b22148..fcc835cd 100644 --- a/folly/wangle/concurrent/CPUThreadPoolExecutor.cpp +++ b/folly/wangle/concurrent/CPUThreadPoolExecutor.cpp @@ -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) + : CPUThreadPoolExecutor( + numThreads, + folly::make_unique>( + numPriorities, + maxQueueSize), + std::move(threadFactory)) {} + CPUThreadPoolExecutor::~CPUThreadPoolExecutor() { stop(); CHECK(threadsToStop_ == 0); diff --git a/folly/wangle/concurrent/CPUThreadPoolExecutor.h b/folly/wangle/concurrent/CPUThreadPoolExecutor.h index bd37d324..56833e22 100644 --- a/folly/wangle/concurrent/CPUThreadPoolExecutor.h +++ b/folly/wangle/concurrent/CPUThreadPoolExecutor.h @@ -42,6 +42,13 @@ class CPUThreadPoolExecutor : public ThreadPoolExecutor { std::shared_ptr threadFactory = std::make_shared("CPUThreadPool")); + explicit CPUThreadPoolExecutor( + size_t numThreads, + uint32_t numPriorities, + size_t maxQueueSize, + std::shared_ptr threadFactory = + std::make_shared("CPUThreadPool")); + ~CPUThreadPoolExecutor(); void add(Func func) override; -- 2.34.1