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
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(),
return thread;
}
+ void setNamePrefix(folly::StringPiece prefix) {
+ prefix_ = std::move(prefix);
+ }
+
private:
folly::StringPiece prefix_;
std::atomic<uint64_t> suffix_;
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();