Commit c16a74ff authored by James Sedgwick's avatar James Sedgwick Committed by Pavlo Kushnir

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
parent 4f204c1f
...@@ -24,9 +24,9 @@ namespace folly { namespace wangle { ...@@ -24,9 +24,9 @@ namespace folly { namespace wangle {
class NamedThreadFactory : public ThreadFactory { class NamedThreadFactory : public ThreadFactory {
public: public:
explicit NamedThreadFactory(folly::StringPiece prefix) 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)); auto thread = std::thread(std::move(func));
folly::setThreadName( folly::setThreadName(
thread.native_handle(), thread.native_handle(),
...@@ -34,6 +34,10 @@ class NamedThreadFactory : public ThreadFactory { ...@@ -34,6 +34,10 @@ class NamedThreadFactory : public ThreadFactory {
return thread; return thread;
} }
void setNamePrefix(folly::StringPiece prefix) {
prefix_ = std::move(prefix);
}
private: private:
folly::StringPiece prefix_; folly::StringPiece prefix_;
std::atomic<uint64_t> suffix_; std::atomic<uint64_t> suffix_;
......
...@@ -45,6 +45,11 @@ class ThreadPoolExecutor : public Executor { ...@@ -45,6 +45,11 @@ class ThreadPoolExecutor : public Executor {
std::chrono::milliseconds expiration, std::chrono::milliseconds expiration,
Func expireCallback) = 0; Func expireCallback) = 0;
void setThreadFactory(std::shared_ptr<ThreadFactory> threadFactory) {
CHECK(numThreads() == 0);
threadFactory_ = std::move(threadFactory);
}
size_t numThreads(); size_t numThreads();
void setNumThreads(size_t numThreads); void setNumThreads(size_t numThreads);
void stop(); void stop();
......
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