Commit cecc9aaa authored by Yuri Putivsky's avatar Yuri Putivsky Committed by afrind

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
parent 3e3afca6
......@@ -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);
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment