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 Initialize(); | 358 bool is_worker_thread) { |
| 359 if (is_worker_thread) | |
|
Lei Zhang
2016/05/12 19:47:40
Instead of adding another parameter, can the calle
Zhenyu Shan
2016/05/16 02:05:35
Done.
| |
| 360 return; | |
| 361 EnsureTlsInitialization(); | |
| 359 ThreadData* current_thread_data = | 362 ThreadData* current_thread_data = |
| 360 reinterpret_cast<ThreadData*>(tls_index_.Get()); | 363 reinterpret_cast<ThreadData*>(tls_index_.Get()); |
| 361 if (current_thread_data) | 364 if (current_thread_data) |
| 362 return; // Browser tests instigate this. | 365 return; // Browser tests instigate this. |
| 363 current_thread_data = new ThreadData(suggested_name); | 366 current_thread_data = new ThreadData(suggested_name); |
| 364 tls_index_.Set(current_thread_data); | 367 tls_index_.Set(current_thread_data); |
| 365 } | 368 } |
| 366 | 369 |
| 367 // static | 370 // static |
| 368 ThreadData* ThreadData::Get() { | 371 ThreadData* ThreadData::Get() { |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 } | 665 } |
| 663 | 666 |
| 664 void ThreadData::OnProfilingPhaseCompletedOnThread(int profiling_phase) { | 667 void ThreadData::OnProfilingPhaseCompletedOnThread(int profiling_phase) { |
| 665 base::AutoLock lock(map_lock_); | 668 base::AutoLock lock(map_lock_); |
| 666 | 669 |
| 667 for (auto& death : death_map_) { | 670 for (auto& death : death_map_) { |
| 668 death.second.OnProfilingPhaseCompleted(profiling_phase); | 671 death.second.OnProfilingPhaseCompleted(profiling_phase); |
| 669 } | 672 } |
| 670 } | 673 } |
| 671 | 674 |
| 672 void ThreadData::Initialize() { | 675 void ThreadData::EnsureTlsInitialization() { |
| 673 if (base::subtle::Acquire_Load(&status_) >= DEACTIVATED) | 676 if (base::subtle::Acquire_Load(&status_) >= DEACTIVATED) |
| 674 return; // Someone else did the initialization. | 677 return; // Someone else did the initialization. |
| 675 // Due to racy lazy initialization in tests, we'll need to recheck status_ | 678 // Due to racy lazy initialization in tests, we'll need to recheck status_ |
| 676 // after we acquire the lock. | 679 // after we acquire the lock. |
| 677 | 680 |
| 678 // Ensure that we don't double initialize tls. We are called when single | 681 // Ensure that we don't double initialize tls. We are called when single |
| 679 // threaded in the product, but some tests may be racy and lazy about our | 682 // threaded in the product, but some tests may be racy and lazy about our |
| 680 // initialization. | 683 // initialization. |
| 681 base::AutoLock lock(*list_lock_.Pointer()); | 684 base::AutoLock lock(*list_lock_.Pointer()); |
| 682 if (base::subtle::Acquire_Load(&status_) >= DEACTIVATED) | 685 if (base::subtle::Acquire_Load(&status_) >= DEACTIVATED) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 702 // we get the lock earlier in this method. | 705 // we get the lock earlier in this method. |
| 703 base::subtle::Release_Store(&status_, kInitialStartupState); | 706 base::subtle::Release_Store(&status_, kInitialStartupState); |
| 704 DCHECK(base::subtle::NoBarrier_Load(&status_) != UNINITIALIZED); | 707 DCHECK(base::subtle::NoBarrier_Load(&status_) != UNINITIALIZED); |
| 705 } | 708 } |
| 706 | 709 |
| 707 // static | 710 // static |
| 708 void ThreadData::InitializeAndSetTrackingStatus(Status status) { | 711 void ThreadData::InitializeAndSetTrackingStatus(Status status) { |
| 709 DCHECK_GE(status, DEACTIVATED); | 712 DCHECK_GE(status, DEACTIVATED); |
| 710 DCHECK_LE(status, PROFILING_ACTIVE); | 713 DCHECK_LE(status, PROFILING_ACTIVE); |
| 711 | 714 |
| 712 Initialize(); // No-op if already initialized. | 715 EnsureTlsInitialization(); // No-op if already initialized. |
| 713 | 716 |
| 714 if (status > DEACTIVATED) | 717 if (status > DEACTIVATED) |
| 715 status = PROFILING_ACTIVE; | 718 status = PROFILING_ACTIVE; |
| 716 base::subtle::Release_Store(&status_, status); | 719 base::subtle::Release_Store(&status_, status); |
| 717 } | 720 } |
| 718 | 721 |
| 719 // static | 722 // static |
| 720 ThreadData::Status ThreadData::status() { | 723 ThreadData::Status ThreadData::status() { |
| 721 return static_cast<ThreadData::Status>(base::subtle::Acquire_Load(&status_)); | 724 return static_cast<ThreadData::Status>(base::subtle::Acquire_Load(&status_)); |
| 722 } | 725 } |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 968 #endif | 971 #endif |
| 969 } | 972 } |
| 970 | 973 |
| 971 ProcessDataSnapshot::ProcessDataSnapshot(const ProcessDataSnapshot& other) = | 974 ProcessDataSnapshot::ProcessDataSnapshot(const ProcessDataSnapshot& other) = |
| 972 default; | 975 default; |
| 973 | 976 |
| 974 ProcessDataSnapshot::~ProcessDataSnapshot() { | 977 ProcessDataSnapshot::~ProcessDataSnapshot() { |
| 975 } | 978 } |
| 976 | 979 |
| 977 } // namespace tracked_objects | 980 } // namespace tracked_objects |
| OLD | NEW |