Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/tracked_objects.h" | 5 #include "base/tracked_objects.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 | 347 |
| 348 // static | 348 // static |
| 349 ThreadData* ThreadData::first() { | 349 ThreadData* ThreadData::first() { |
| 350 base::AutoLock lock(*list_lock_.Pointer()); | 350 base::AutoLock lock(*list_lock_.Pointer()); |
| 351 return all_thread_data_list_head_; | 351 return all_thread_data_list_head_; |
| 352 } | 352 } |
| 353 | 353 |
| 354 ThreadData* ThreadData::next() const { return next_; } | 354 ThreadData* ThreadData::next() const { return next_; } |
| 355 | 355 |
| 356 // static | 356 // static |
| 357 void ThreadData::InitializeThreadContext(const std::string& suggested_name) { | 357 void ThreadData::InitializeThreadContext(const std::string& suggested_name, |
| 358 bool is_worker_thread) { | |
|
dcheng
2016/04/01 10:52:30
Interesting, the original assumption is that worke
| |
| 358 Initialize(); | 359 Initialize(); |
| 359 ThreadData* current_thread_data = | 360 ThreadData* current_thread_data = |
| 360 reinterpret_cast<ThreadData*>(tls_index_.Get()); | 361 reinterpret_cast<ThreadData*>(tls_index_.Get()); |
| 361 if (current_thread_data) | 362 if (current_thread_data) |
| 362 return; // Browser tests instigate this. | 363 return; // Browser tests instigate this. |
| 363 current_thread_data = new ThreadData(suggested_name); | 364 |
| 365 if (is_worker_thread) { | |
|
dcheng
2016/04/01 10:52:30
Can we just early return at the beginning for work
| |
| 366 // Try to reuse retired worker thread data first | |
| 367 if (first_retired_worker_) { | |
| 368 current_thread_data = first_retired_worker_; | |
| 369 first_retired_worker_ = first_retired_worker_->next_retired_worker_; | |
| 370 current_thread_data->next_retired_worker_ = NULL; | |
| 371 } else { | |
| 372 int worker_thread_number = ++worker_thread_data_creation_count_; | |
| 373 DCHECK_GT(worker_thread_number, 0); | |
| 374 current_thread_data = new ThreadData(worker_thread_number); | |
| 375 } | |
| 376 DCHECK_GT(current_thread_data->worker_thread_number_, 0); | |
| 377 } | |
| 378 else { | |
| 379 current_thread_data = new ThreadData(suggested_name); | |
| 380 } | |
| 381 | |
| 382 DCHECK(current_thread_data); | |
| 364 tls_index_.Set(current_thread_data); | 383 tls_index_.Set(current_thread_data); |
| 365 } | 384 } |
| 366 | 385 |
| 367 // static | 386 // static |
| 368 ThreadData* ThreadData::Get() { | 387 ThreadData* ThreadData::Get() { |
| 369 if (!tls_index_.initialized()) | 388 if (!tls_index_.initialized()) |
| 370 return NULL; // For unittests only. | 389 return NULL; // For unittests only. |
| 371 ThreadData* registered = reinterpret_cast<ThreadData*>(tls_index_.Get()); | 390 ThreadData* registered = reinterpret_cast<ThreadData*>(tls_index_.Get()); |
| 372 if (registered) | 391 if (registered) |
| 373 return registered; | 392 return registered; |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 968 #endif | 987 #endif |
| 969 } | 988 } |
| 970 | 989 |
| 971 ProcessDataSnapshot::ProcessDataSnapshot(const ProcessDataSnapshot& other) = | 990 ProcessDataSnapshot::ProcessDataSnapshot(const ProcessDataSnapshot& other) = |
| 972 default; | 991 default; |
| 973 | 992 |
| 974 ProcessDataSnapshot::~ProcessDataSnapshot() { | 993 ProcessDataSnapshot::~ProcessDataSnapshot() { |
| 975 } | 994 } |
| 976 | 995 |
| 977 } // namespace tracked_objects | 996 } // namespace tracked_objects |
| OLD | NEW |