Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(853)

Side by Side Diff: base/tracked_objects.cc

Issue 1845753006: Don't create redundant ThreadData for Worker Threads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update comment Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 EnsureTlsInitialization();
359 ThreadData* current_thread_data = 359 ThreadData* current_thread_data =
360 reinterpret_cast<ThreadData*>(tls_index_.Get()); 360 reinterpret_cast<ThreadData*>(tls_index_.Get());
361 if (current_thread_data) 361 if (current_thread_data)
362 return; // Browser tests instigate this. 362 return; // Browser tests instigate this.
363 current_thread_data = new ThreadData(suggested_name); 363 current_thread_data = new ThreadData(suggested_name);
364 tls_index_.Set(current_thread_data); 364 tls_index_.Set(current_thread_data);
365 } 365 }
366 366
367 // static 367 // static
368 ThreadData* ThreadData::Get() { 368 ThreadData* ThreadData::Get() {
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 } 662 }
663 663
664 void ThreadData::OnProfilingPhaseCompletedOnThread(int profiling_phase) { 664 void ThreadData::OnProfilingPhaseCompletedOnThread(int profiling_phase) {
665 base::AutoLock lock(map_lock_); 665 base::AutoLock lock(map_lock_);
666 666
667 for (auto& death : death_map_) { 667 for (auto& death : death_map_) {
668 death.second.OnProfilingPhaseCompleted(profiling_phase); 668 death.second.OnProfilingPhaseCompleted(profiling_phase);
669 } 669 }
670 } 670 }
671 671
672 void ThreadData::Initialize() { 672 void ThreadData::EnsureTlsInitialization() {
673 if (base::subtle::Acquire_Load(&status_) >= DEACTIVATED) 673 if (base::subtle::Acquire_Load(&status_) >= DEACTIVATED)
674 return; // Someone else did the initialization. 674 return; // Someone else did the initialization.
675 // Due to racy lazy initialization in tests, we'll need to recheck status_ 675 // Due to racy lazy initialization in tests, we'll need to recheck status_
676 // after we acquire the lock. 676 // after we acquire the lock.
677 677
678 // Ensure that we don't double initialize tls. We are called when single 678 // 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 679 // threaded in the product, but some tests may be racy and lazy about our
680 // initialization. 680 // initialization.
681 base::AutoLock lock(*list_lock_.Pointer()); 681 base::AutoLock lock(*list_lock_.Pointer());
682 if (base::subtle::Acquire_Load(&status_) >= DEACTIVATED) 682 if (base::subtle::Acquire_Load(&status_) >= DEACTIVATED)
(...skipping 19 matching lines...) Expand all
702 // we get the lock earlier in this method. 702 // we get the lock earlier in this method.
703 base::subtle::Release_Store(&status_, kInitialStartupState); 703 base::subtle::Release_Store(&status_, kInitialStartupState);
704 DCHECK(base::subtle::NoBarrier_Load(&status_) != UNINITIALIZED); 704 DCHECK(base::subtle::NoBarrier_Load(&status_) != UNINITIALIZED);
705 } 705 }
706 706
707 // static 707 // static
708 void ThreadData::InitializeAndSetTrackingStatus(Status status) { 708 void ThreadData::InitializeAndSetTrackingStatus(Status status) {
709 DCHECK_GE(status, DEACTIVATED); 709 DCHECK_GE(status, DEACTIVATED);
710 DCHECK_LE(status, PROFILING_ACTIVE); 710 DCHECK_LE(status, PROFILING_ACTIVE);
711 711
712 Initialize(); // No-op if already initialized. 712 EnsureTlsInitialization(); // No-op if already initialized.
713 713
714 if (status > DEACTIVATED) 714 if (status > DEACTIVATED)
715 status = PROFILING_ACTIVE; 715 status = PROFILING_ACTIVE;
716 base::subtle::Release_Store(&status_, status); 716 base::subtle::Release_Store(&status_, status);
717 } 717 }
718 718
719 // static 719 // static
720 ThreadData::Status ThreadData::status() { 720 ThreadData::Status ThreadData::status() {
721 return static_cast<ThreadData::Status>(base::subtle::Acquire_Load(&status_)); 721 return static_cast<ThreadData::Status>(base::subtle::Acquire_Load(&status_));
722 } 722 }
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 #endif 968 #endif
969 } 969 }
970 970
971 ProcessDataSnapshot::ProcessDataSnapshot(const ProcessDataSnapshot& other) = 971 ProcessDataSnapshot::ProcessDataSnapshot(const ProcessDataSnapshot& other) =
972 default; 972 default;
973 973
974 ProcessDataSnapshot::~ProcessDataSnapshot() { 974 ProcessDataSnapshot::~ProcessDataSnapshot() {
975 } 975 }
976 976
977 } // namespace tracked_objects 977 } // namespace tracked_objects
OLDNEW
« base/threading/platform_thread_linux.cc ('K') | « base/tracked_objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698