From cecc9aaa38ead8b3ff42e7644a4a6764037cd3c9 Mon Sep 17 00:00:00 2001 From: Yuri Putivsky Date: Fri, 27 Mar 2015 18:20:44 -0700 Subject: [PATCH] Extend IO pool with external optional event_base_manager Summary: as title Test Plan: run unit tests Reviewed By: yfeldblum@fb.com Subscribers: ming, fugalh, folly-diffs@, jsedgwick, yfeldblum, chalfant FB internal diff: D1950610 --- folly/wangle/concurrent/IOThreadPoolExecutor.cpp | 10 +++++----- folly/wangle/concurrent/IOThreadPoolExecutor.h | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/folly/wangle/concurrent/IOThreadPoolExecutor.cpp b/folly/wangle/concurrent/IOThreadPoolExecutor.cpp index 2fb649d1..4ac0b79b 100644 --- a/folly/wangle/concurrent/IOThreadPoolExecutor.cpp +++ b/folly/wangle/concurrent/IOThreadPoolExecutor.cpp @@ -18,7 +18,6 @@ #include #include -#include #include @@ -65,9 +64,11 @@ class MemoryIdlerTimeout IOThreadPoolExecutor::IOThreadPoolExecutor( size_t numThreads, - std::shared_ptr threadFactory) + std::shared_ptr threadFactory, + EventBaseManager* ebm) : ThreadPoolExecutor(numThreads, std::move(threadFactory)), - nextThread_(0) { + nextThread_(0), + eventBaseManager_(ebm) { addThreads(numThreads); CHECK(threadList_.get().size() == numThreads); } @@ -135,8 +136,7 @@ IOThreadPoolExecutor::makeThread() { void IOThreadPoolExecutor::threadRun(ThreadPtr thread) { const auto ioThread = std::static_pointer_cast(thread); - ioThread->eventBase = - folly::EventBaseManager::get()->getEventBase(); + ioThread->eventBase = eventBaseManager_->getEventBase(); thisThread_.reset(new std::shared_ptr(ioThread)); auto idler = new MemoryIdlerTimeout(ioThread->eventBase); diff --git a/folly/wangle/concurrent/IOThreadPoolExecutor.h b/folly/wangle/concurrent/IOThreadPoolExecutor.h index f3c5865f..00aaa477 100644 --- a/folly/wangle/concurrent/IOThreadPoolExecutor.h +++ b/folly/wangle/concurrent/IOThreadPoolExecutor.h @@ -16,7 +16,7 @@ #pragma once -#include +#include #include #include @@ -29,7 +29,8 @@ class IOThreadPoolExecutor : public ThreadPoolExecutor, public IOExecutor { explicit IOThreadPoolExecutor( size_t numThreads, std::shared_ptr threadFactory = - std::make_shared("IOThreadPool")); + std::make_shared("IOThreadPool"), + EventBaseManager* ebm = folly::EventBaseManager::get()); ~IOThreadPoolExecutor(); @@ -62,6 +63,7 @@ class IOThreadPoolExecutor : public ThreadPoolExecutor, public IOExecutor { size_t nextThread_; ThreadLocal> thisThread_; + EventBaseManager* eventBaseManager_; }; }} // folly::wangle -- 2.34.1