From: James Sedgwick Date: Mon, 3 Nov 2014 00:28:49 +0000 (-0800) Subject: Name prefix setter for NamedThreadFactory X-Git-Tag: v0.22.0~203 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=c16a74ffe9151e91bf2ed62ebc276d938a8688fb Name prefix setter for NamedThreadFactory 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 --- diff --git a/folly/experimental/wangle/concurrent/NamedThreadFactory.h b/folly/experimental/wangle/concurrent/NamedThreadFactory.h index 5c513c51..e01b8755 100644 --- a/folly/experimental/wangle/concurrent/NamedThreadFactory.h +++ b/folly/experimental/wangle/concurrent/NamedThreadFactory.h @@ -24,9 +24,9 @@ namespace folly { namespace wangle { 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(), @@ -34,6 +34,10 @@ class NamedThreadFactory : public ThreadFactory { return thread; } + void setNamePrefix(folly::StringPiece prefix) { + prefix_ = std::move(prefix); + } + private: folly::StringPiece prefix_; std::atomic suffix_; diff --git a/folly/experimental/wangle/concurrent/ThreadPoolExecutor.h b/folly/experimental/wangle/concurrent/ThreadPoolExecutor.h index 84b61051..68da850a 100644 --- a/folly/experimental/wangle/concurrent/ThreadPoolExecutor.h +++ b/folly/experimental/wangle/concurrent/ThreadPoolExecutor.h @@ -45,6 +45,11 @@ class ThreadPoolExecutor : public Executor { std::chrono::milliseconds expiration, Func expireCallback) = 0; + void setThreadFactory(std::shared_ptr threadFactory) { + CHECK(numThreads() == 0); + threadFactory_ = std::move(threadFactory); + } + size_t numThreads(); void setNumThreads(size_t numThreads); void stop();