Commit fead66ff authored by Carlos Caballero's avatar Carlos Caballero Committed by Commit Bot

Remove tid suffix from name in SimpleThread

This is not really needed, as tracing will keep track of the tid in a
dedicated field. Also it makes it harder for test ifrastructure to find
a given thread (prefix match instead vs exact match). Some current
infrastructure uses exact match and thus threads created with
SimpleThread might not get accounted for correctly (e.g. see bug)

If it turns out that that client code really needs this we could add
support for a placeholder %tid in the name.

Bug: 954579
Change-Id: Ibd595463d8421891616000c1d518f5bbcf95e046
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1578539Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Carlos Caballero <carlscab@google.com>
Cr-Commit-Position: refs/heads/master@{#653527}
parent cf54903d
......@@ -11,12 +11,11 @@
namespace base {
SimpleThread::SimpleThread(const std::string& name_prefix)
: SimpleThread(name_prefix, Options()) {}
SimpleThread::SimpleThread(const std::string& name)
: SimpleThread(name, Options()) {}
SimpleThread::SimpleThread(const std::string& name_prefix,
const Options& options)
: name_prefix_(name_prefix),
SimpleThread::SimpleThread(const std::string& name, const Options& options)
: name_(name),
options_(options),
event_(WaitableEvent::ResetPolicy::MANUAL,
WaitableEvent::InitialState::NOT_SIGNALED) {}
......@@ -67,11 +66,7 @@ bool SimpleThread::HasBeenStarted() {
void SimpleThread::ThreadMain() {
tid_ = PlatformThread::CurrentId();
// Construct our full name of the form "name_prefix_/TID".
std::string name(name_prefix_);
name.push_back('/');
name.append(NumberToString(tid_));
PlatformThread::SetName(name);
PlatformThread::SetName(name_);
// We've initialized our new thread, signal that we're done to Start().
event_.Signal();
......@@ -81,14 +76,13 @@ void SimpleThread::ThreadMain() {
}
DelegateSimpleThread::DelegateSimpleThread(Delegate* delegate,
const std::string& name_prefix)
: DelegateSimpleThread(delegate, name_prefix, Options()) {}
const std::string& name)
: DelegateSimpleThread(delegate, name, Options()) {}
DelegateSimpleThread::DelegateSimpleThread(Delegate* delegate,
const std::string& name_prefix,
const std::string& name,
const Options& options)
: SimpleThread(name_prefix, options),
delegate_(delegate) {
: SimpleThread(name, options), delegate_(delegate) {
DCHECK(delegate_);
}
......@@ -121,7 +115,10 @@ DelegateSimpleThreadPool::~DelegateSimpleThreadPool() {
void DelegateSimpleThreadPool::Start() {
DCHECK(threads_.empty()) << "Start() called with outstanding threads.";
for (int i = 0; i < num_threads_; ++i) {
DelegateSimpleThread* thread = new DelegateSimpleThread(this, name_prefix_);
std::string name(name_prefix_);
name.push_back('/');
name.append(NumberToString(i));
DelegateSimpleThread* thread = new DelegateSimpleThread(this, name);
thread->Start();
threads_.push_back(thread);
}
......
......@@ -81,12 +81,12 @@ class BASE_EXPORT SimpleThread : public PlatformThread::Delegate {
bool joinable = true;
};
// Create a SimpleThread. |options| should be used to manage any specific
// Creates a SimpleThread. |options| should be used to manage any specific
// configuration involving the thread creation and management.
// Every thread has a name, in the form of |name_prefix|/TID, for example
// "my_thread/321". The thread will not be created until Start() is called.
explicit SimpleThread(const std::string& name_prefix);
SimpleThread(const std::string& name_prefix, const Options& options);
// Every thread has a name, which is a display string to identify the thread.
// The thread will not be created until Start() is called.
explicit SimpleThread(const std::string& name);
SimpleThread(const std::string& name, const Options& options);
~SimpleThread() override;
......@@ -140,8 +140,7 @@ class BASE_EXPORT SimpleThread : public PlatformThread::Delegate {
// has been initialized before this is called.
virtual void BeforeJoin() {}
const std::string name_prefix_;
std::string name_;
const std::string name_;
const Options options_;
PlatformThreadHandle thread_; // PlatformThread handle, reset after Join.
WaitableEvent event_; // Signaled if Start() was ever called.
......
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