Name prefix setter for NamedThreadFactory
authorJames Sedgwick <jsedgwick@fb.com>
Mon, 3 Nov 2014 00:28:49 +0000 (16:28 -0800)
committerPavlo Kushnir <pavlo@fb.com>
Sat, 8 Nov 2014 02:29:07 +0000 (18:29 -0800)
Summary: it's useful to update the prefix after the construction.

Test Plan:
unit, that's it :/

Reviewed By: davejwatson@fb.com

Subscribers: mshneer, folly-diffs@, wch, atlas2-eng@, everstore-dev@, wormhole-diffs@, ads-dsp-eng@, bwester, trunkagent, fugalh, alandau, njormrod, bmatheny

FB internal diff: D1585087

folly/experimental/wangle/concurrent/NamedThreadFactory.h
folly/experimental/wangle/concurrent/ThreadPoolExecutor.h

index 5c513c51fa447c52478b1809d98097c73253400c..e01b87554683415f0ff68ce9228f02dae4f8f284 100644 (file)
@@ -24,9 +24,9 @@ namespace folly { namespace wangle {
 class NamedThreadFactory : public ThreadFactory {
  public:
   explicit NamedThreadFactory(folly::StringPiece prefix)
 class NamedThreadFactory : public ThreadFactory {
  public:
   explicit NamedThreadFactory(folly::StringPiece prefix)
-    : prefix_(prefix), suffix_(0) {}
+    : prefix_(std::move(prefix)), suffix_(0) {}
 
 
-  std::thread newThread(Func&& func) override {
+  virtual std::thread newThread(Func&& func) override {
     auto thread = std::thread(std::move(func));
     folly::setThreadName(
         thread.native_handle(),
     auto thread = std::thread(std::move(func));
     folly::setThreadName(
         thread.native_handle(),
@@ -34,6 +34,10 @@ class NamedThreadFactory : public ThreadFactory {
     return thread;
   }
 
     return thread;
   }
 
+  void setNamePrefix(folly::StringPiece prefix) {
+    prefix_ = std::move(prefix);
+  }
+
  private:
   folly::StringPiece prefix_;
   std::atomic<uint64_t> suffix_;
  private:
   folly::StringPiece prefix_;
   std::atomic<uint64_t> suffix_;
index 84b61051cefd6838a14a127e80955bce048911ee..68da850ab5aa215858430e8cc1cd8c6e7b02556b 100644 (file)
@@ -45,6 +45,11 @@ class ThreadPoolExecutor : public Executor {
       std::chrono::milliseconds expiration,
       Func expireCallback) = 0;
 
       std::chrono::milliseconds expiration,
       Func expireCallback) = 0;
 
+  void setThreadFactory(std::shared_ptr<ThreadFactory> threadFactory) {
+    CHECK(numThreads() == 0);
+    threadFactory_ = std::move(threadFactory);
+  }
+
   size_t numThreads();
   void setNumThreads(size_t numThreads);
   void stop();
   size_t numThreads();
   void setNumThreads(size_t numThreads);
   void stop();