From 8b3f89ae47aa4bd2bd1be0507c2483ca3d267993 Mon Sep 17 00:00:00 2001 From: Dave Watson Date: Thu, 18 Dec 2014 09:48:05 -0800 Subject: [PATCH] remove Cpp2WorkerFactory Summary: In preparation for a global IOThreadPoolExecutor - we can't override the workerFactory if we are using a global one. Instead, add a new getEventBases() to IOTHreadPoolExecutro and just run code on each eventBase. For shutdown, explicitly add a stop(), instead of doing the work after loop() as exited Cpp2Worker required minor changes to be able to use EventBaseManager's eventbase vs. their own Test Plan: fbconfig -r thrift/lib/cpp2; fbmake runtests Reviewed By: jsedgwick@fb.com Subscribers: trunkagent, andrewcox, doug, fugalh, alandau, bmatheny, mshneer, folly-diffs@ FB internal diff: D1734795 Signature: t1:1734795:1418759367:b45f419e5cbc482a64a5873d9e00e3bcb071db5a --- .../wangle/concurrent/IOThreadPoolExecutor.cpp | 10 ++++++++++ .../wangle/concurrent/IOThreadPoolExecutor.h | 2 ++ .../wangle/concurrent/NamedThreadFactory.h | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/folly/experimental/wangle/concurrent/IOThreadPoolExecutor.cpp b/folly/experimental/wangle/concurrent/IOThreadPoolExecutor.cpp index 73b5c61f..f1fa3904 100644 --- a/folly/experimental/wangle/concurrent/IOThreadPoolExecutor.cpp +++ b/folly/experimental/wangle/concurrent/IOThreadPoolExecutor.cpp @@ -153,6 +153,16 @@ void IOThreadPoolExecutor::stopThreads(size_t n) { } } +std::vector IOThreadPoolExecutor::getEventBases() { + std::vector bases; + RWSpinLock::ReadHolder{&threadListLock_}; + for (const auto& thread : threadList_.get()) { + auto ioThread = std::static_pointer_cast(thread); + bases.push_back(ioThread->eventBase); + } + return bases; +} + // threadListLock_ is readlocked uint64_t IOThreadPoolExecutor::getPendingTaskCount() { uint64_t count = 0; diff --git a/folly/experimental/wangle/concurrent/IOThreadPoolExecutor.h b/folly/experimental/wangle/concurrent/IOThreadPoolExecutor.h index 0fde4a29..9196ef6d 100644 --- a/folly/experimental/wangle/concurrent/IOThreadPoolExecutor.h +++ b/folly/experimental/wangle/concurrent/IOThreadPoolExecutor.h @@ -41,6 +41,8 @@ class IOThreadPoolExecutor : public ThreadPoolExecutor, public IOExecutor { EventBase* getEventBase() override; + std::vector getEventBases(); + private: struct FOLLY_ALIGN_TO_AVOID_FALSE_SHARING IOThread : public Thread { IOThread(IOThreadPoolExecutor* pool) diff --git a/folly/experimental/wangle/concurrent/NamedThreadFactory.h b/folly/experimental/wangle/concurrent/NamedThreadFactory.h index 3a6ed05b..2bb5579b 100644 --- a/folly/experimental/wangle/concurrent/NamedThreadFactory.h +++ b/folly/experimental/wangle/concurrent/NamedThreadFactory.h @@ -44,6 +44,10 @@ class NamedThreadFactory : public ThreadFactory { prefix_ = prefix.str(); } + std::string getNamePrefix() { + return prefix_; + } + private: std::string prefix_; std::atomic suffix_; -- 2.34.1