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

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: Created 4 years, 6 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
« no previous file with comments | « base/tracked_objects.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/base_switches.h" 11 #include "base/base_switches.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/debug/leak_annotations.h" 14 #include "base/debug/leak_annotations.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/process/process_handle.h" 16 #include "base/process/process_handle.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "base/third_party/valgrind/memcheck.h" 18 #include "base/third_party/valgrind/memcheck.h"
19 #include "base/threading/worker_pool.h"
19 #include "base/tracking_info.h" 20 #include "base/tracking_info.h"
20 #include "build/build_config.h" 21 #include "build/build_config.h"
21 22
22 using base::TimeDelta; 23 using base::TimeDelta;
23 24
24 namespace base { 25 namespace base {
25 class TimeDelta; 26 class TimeDelta;
26 } 27 }
27 28
28 namespace tracked_objects { 29 namespace tracked_objects {
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 // static 349 // static
349 ThreadData* ThreadData::first() { 350 ThreadData* ThreadData::first() {
350 base::AutoLock lock(*list_lock_.Pointer()); 351 base::AutoLock lock(*list_lock_.Pointer());
351 return all_thread_data_list_head_; 352 return all_thread_data_list_head_;
352 } 353 }
353 354
354 ThreadData* ThreadData::next() const { return next_; } 355 ThreadData* ThreadData::next() const { return next_; }
355 356
356 // static 357 // static
357 void ThreadData::InitializeThreadContext(const std::string& suggested_name) { 358 void ThreadData::InitializeThreadContext(const std::string& suggested_name) {
358 Initialize(); 359 if (base::WorkerPool::RunsTasksOnCurrentThread())
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
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
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
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
OLDNEW
« no previous file with comments | « base/tracked_objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698