remove Cpp2WorkerFactory
authorDave Watson <davejwatson@fb.com>
Thu, 18 Dec 2014 17:48:05 +0000 (09:48 -0800)
committerJoelMarcey <joelm@fb.com>
Thu, 18 Dec 2014 20:29:41 +0000 (12:29 -0800)
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

folly/experimental/wangle/concurrent/IOThreadPoolExecutor.cpp
folly/experimental/wangle/concurrent/IOThreadPoolExecutor.h
folly/experimental/wangle/concurrent/NamedThreadFactory.h

index 73b5c61f26377c3139107fb4d10e24a946e4cfb2..f1fa39040c83342cee6ad257f04c5e4844a3de00 100644 (file)
@@ -153,6 +153,16 @@ void IOThreadPoolExecutor::stopThreads(size_t n) {
   }
 }
 
+std::vector<EventBase*> IOThreadPoolExecutor::getEventBases() {
+  std::vector<EventBase*> bases;
+  RWSpinLock::ReadHolder{&threadListLock_};
+  for (const auto& thread : threadList_.get()) {
+    auto ioThread = std::static_pointer_cast<IOThread>(thread);
+    bases.push_back(ioThread->eventBase);
+  }
+  return bases;
+}
+
 // threadListLock_ is readlocked
 uint64_t IOThreadPoolExecutor::getPendingTaskCount() {
   uint64_t count = 0;
index 0fde4a2953974f4cb06cba32cd9c77accbba0952..9196ef6d37d3cfb1a2b23741f1cf2a1840169abf 100644 (file)
@@ -41,6 +41,8 @@ class IOThreadPoolExecutor : public ThreadPoolExecutor, public IOExecutor {
 
   EventBase* getEventBase() override;
 
+  std::vector<EventBase*> getEventBases();
+
  private:
   struct FOLLY_ALIGN_TO_AVOID_FALSE_SHARING IOThread : public Thread {
     IOThread(IOThreadPoolExecutor* pool)
index 3a6ed05bcd17450e1d3635d53eda4889902efab0..2bb5579ba7e3a5268a7c8d8c3dcd5bd9b39c3efb 100644 (file)
@@ -44,6 +44,10 @@ class NamedThreadFactory : public ThreadFactory {
     prefix_ = prefix.str();
   }
 
+  std::string getNamePrefix() {
+    return prefix_;
+  }
+
  private:
   std::string prefix_;
   std::atomic<uint64_t> suffix_;