Commit 773fa87a authored by Lucian Grijincu's avatar Lucian Grijincu Committed by Pavlo Kushnir

folly: wangle: NamedThreadFactory: store of the thread prefix locally, don't...

folly: wangle: NamedThreadFactory: store of the thread prefix locally, don't assume they'll live forever

Summary: There's no real reason to store this as a StringPiece, is there?

Test Plan: n/a

Reviewed By: sdoroshenko@fb.com, robot9@fb.com

Subscribers: fugalh, njormrod, folly-diffs@

FB internal diff: D1659558

Tasks: 5538418

Signature: t1:1659558:1415147560:2c5b0c996893854c3ea9d0ad02b006bcc5960ffa
parent 1bd2c005
......@@ -15,8 +15,14 @@
*/
#pragma once
#include <atomic>
#include <string>
#include <thread>
#include <folly/experimental/wangle/concurrent/ThreadFactory.h>
#include <folly/Conv.h>
#include <folly/Range.h>
#include <folly/ThreadName.h>
namespace folly { namespace wangle {
......@@ -24,9 +30,9 @@ namespace folly { namespace wangle {
class NamedThreadFactory : public ThreadFactory {
public:
explicit NamedThreadFactory(folly::StringPiece prefix)
: prefix_(std::move(prefix)), suffix_(0) {}
: prefix_(prefix.str()), suffix_(0) {}
virtual std::thread newThread(Func&& func) override {
std::thread newThread(Func&& func) override {
auto thread = std::thread(std::move(func));
folly::setThreadName(
thread.native_handle(),
......@@ -35,11 +41,11 @@ class NamedThreadFactory : public ThreadFactory {
}
void setNamePrefix(folly::StringPiece prefix) {
prefix_ = std::move(prefix);
prefix_ = prefix.str();
}
private:
folly::StringPiece prefix_;
std::string prefix_;
std::atomic<uint64_t> suffix_;
};
......
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