Extend IO pool with external optional event_base_manager
authorYuri Putivsky <putivsky@fb.com>
Sat, 28 Mar 2015 01:20:44 +0000 (18:20 -0700)
committerafrind <afrind@fb.com>
Thu, 2 Apr 2015 19:00:29 +0000 (12:00 -0700)
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
folly/wangle/concurrent/IOThreadPoolExecutor.h

index 2fb649d1ab4f9cbb9e9d4478484a083997eaf71b..4ac0b79b7167a6e8805a433de5cc40c48e8035bf 100644 (file)
@@ -18,7 +18,6 @@
 
 #include <folly/MoveWrapper.h>
 #include <glog/logging.h>
-#include <folly/io/async/EventBaseManager.h>
 
 #include <folly/detail/MemoryIdler.h>
 
@@ -65,9 +64,11 @@ class MemoryIdlerTimeout
 
 IOThreadPoolExecutor::IOThreadPoolExecutor(
     size_t numThreads,
-    std::shared_ptr<ThreadFactory> threadFactory)
+    std::shared_ptr<ThreadFactory> 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<IOThread>(thread);
-  ioThread->eventBase =
-    folly::EventBaseManager::get()->getEventBase();
+  ioThread->eventBase = eventBaseManager_->getEventBase();
   thisThread_.reset(new std::shared_ptr<IOThread>(ioThread));
 
   auto idler = new MemoryIdlerTimeout(ioThread->eventBase);
index f3c5865f36c8eb70b8d2e5f8a27e7066d6d4f9bf..00aaa4779c6bc28f1ec535a6e90902a6a54b4283 100644 (file)
@@ -16,7 +16,7 @@
 
 #pragma once
 
-#include <folly/io/async/EventBase.h>
+#include <folly/io/async/EventBaseManager.h>
 #include <folly/wangle/concurrent/IOExecutor.h>
 #include <folly/wangle/concurrent/ThreadPoolExecutor.h>
 
@@ -29,7 +29,8 @@ class IOThreadPoolExecutor : public ThreadPoolExecutor, public IOExecutor {
   explicit IOThreadPoolExecutor(
       size_t numThreads,
       std::shared_ptr<ThreadFactory> threadFactory =
-          std::make_shared<NamedThreadFactory>("IOThreadPool"));
+          std::make_shared<NamedThreadFactory>("IOThreadPool"),
+      EventBaseManager* ebm = folly::EventBaseManager::get());
 
   ~IOThreadPoolExecutor();
 
@@ -62,6 +63,7 @@ class IOThreadPoolExecutor : public ThreadPoolExecutor, public IOExecutor {
 
   size_t nextThread_;
   ThreadLocal<std::shared_ptr<IOThread>> thisThread_;
+  EventBaseManager* eventBaseManager_;
 };
 
 }} // folly::wangle