Chromium Code Reviews| Index: base/tracked_objects.cc |
| diff --git a/base/tracked_objects.cc b/base/tracked_objects.cc |
| index d24cedf159241d58a92909650de374f187dd85ae..81f17e9bdcb09a2bc44566dc066b64aae9fe536c 100644 |
| --- a/base/tracked_objects.cc |
| +++ b/base/tracked_objects.cc |
| @@ -354,13 +354,32 @@ ThreadData* ThreadData::first() { |
| ThreadData* ThreadData::next() const { return next_; } |
| // static |
| -void ThreadData::InitializeThreadContext(const std::string& suggested_name) { |
| +void ThreadData::InitializeThreadContext(const std::string& suggested_name, |
| + bool is_worker_thread) { |
|
dcheng
2016/04/01 10:52:30
Interesting, the original assumption is that worke
|
| Initialize(); |
| ThreadData* current_thread_data = |
| reinterpret_cast<ThreadData*>(tls_index_.Get()); |
| if (current_thread_data) |
| return; // Browser tests instigate this. |
| - current_thread_data = new ThreadData(suggested_name); |
| + |
| + if (is_worker_thread) { |
|
dcheng
2016/04/01 10:52:30
Can we just early return at the beginning for work
|
| + // Try to reuse retired worker thread data first |
| + if (first_retired_worker_) { |
| + current_thread_data = first_retired_worker_; |
| + first_retired_worker_ = first_retired_worker_->next_retired_worker_; |
| + current_thread_data->next_retired_worker_ = NULL; |
| + } else { |
| + int worker_thread_number = ++worker_thread_data_creation_count_; |
| + DCHECK_GT(worker_thread_number, 0); |
| + current_thread_data = new ThreadData(worker_thread_number); |
| + } |
| + DCHECK_GT(current_thread_data->worker_thread_number_, 0); |
| + } |
| + else { |
| + current_thread_data = new ThreadData(suggested_name); |
| + } |
| + |
| + DCHECK(current_thread_data); |
| tls_index_.Set(current_thread_data); |
| } |