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

Side by Side Diff: base/tracked_objects.cc

Issue 1124493002: Cleanup: given that TLS slot can't fail to initialize, remove bool return values (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@parchild
Patch Set: Created 5 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
« no previous file with comments | « base/tracked_objects.h ('k') | base/tracked_objects_unittest.cc » ('j') | 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"
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 // static 381 // static
382 ThreadData* ThreadData::first() { 382 ThreadData* ThreadData::first() {
383 base::AutoLock lock(*list_lock_.Pointer()); 383 base::AutoLock lock(*list_lock_.Pointer());
384 return all_thread_data_list_head_; 384 return all_thread_data_list_head_;
385 } 385 }
386 386
387 ThreadData* ThreadData::next() const { return next_; } 387 ThreadData* ThreadData::next() const { return next_; }
388 388
389 // static 389 // static
390 void ThreadData::InitializeThreadContext(const std::string& suggested_name) { 390 void ThreadData::InitializeThreadContext(const std::string& suggested_name) {
391 if (!Initialize()) // Always initialize if needed. 391 Initialize(); // Always initialize if needed.
cpu_(ooo_6.6-7.5) 2015/05/05 20:49:35 remove 0 new information comment of 391 pls.
392 return;
393 ThreadData* current_thread_data = 392 ThreadData* current_thread_data =
394 reinterpret_cast<ThreadData*>(tls_index_.Get()); 393 reinterpret_cast<ThreadData*>(tls_index_.Get());
395 if (current_thread_data) 394 if (current_thread_data)
396 return; // Browser tests instigate this. 395 return; // Browser tests instigate this.
397 current_thread_data = new ThreadData(suggested_name); 396 current_thread_data = new ThreadData(suggested_name);
398 tls_index_.Set(current_thread_data); 397 tls_index_.Set(current_thread_data);
399 } 398 }
400 399
401 // static 400 // static
402 ThreadData* ThreadData::Get() { 401 ThreadData* ThreadData::Get() {
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 death.second.OnProfilingPhaseCompleted(profiling_phase); 710 death.second.OnProfilingPhaseCompleted(profiling_phase);
712 } 711 }
713 } 712 }
714 713
715 static void OptionallyInitializeAlternateTimer() { 714 static void OptionallyInitializeAlternateTimer() {
716 NowFunction* alternate_time_source = GetAlternateTimeSource(); 715 NowFunction* alternate_time_source = GetAlternateTimeSource();
717 if (alternate_time_source) 716 if (alternate_time_source)
718 ThreadData::SetAlternateTimeSource(alternate_time_source); 717 ThreadData::SetAlternateTimeSource(alternate_time_source);
719 } 718 }
720 719
721 bool ThreadData::Initialize() { 720 void ThreadData::Initialize() {
722 if (status_ >= DEACTIVATED) 721 if (status_ >= DEACTIVATED)
723 return true; // Someone else did the initialization. 722 return; // Someone else did the initialization.
724 // Due to racy lazy initialization in tests, we'll need to recheck status_ 723 // Due to racy lazy initialization in tests, we'll need to recheck status_
725 // after we acquire the lock. 724 // after we acquire the lock.
726 725
727 // Ensure that we don't double initialize tls. We are called when single 726 // Ensure that we don't double initialize tls. We are called when single
728 // threaded in the product, but some tests may be racy and lazy about our 727 // threaded in the product, but some tests may be racy and lazy about our
729 // initialization. 728 // initialization.
730 base::AutoLock lock(*list_lock_.Pointer()); 729 base::AutoLock lock(*list_lock_.Pointer());
731 if (status_ >= DEACTIVATED) 730 if (status_ >= DEACTIVATED)
732 return true; // Someone raced in here and beat us. 731 return; // Someone raced in here and beat us.
733 732
734 // Put an alternate timer in place if the environment calls for it, such as 733 // Put an alternate timer in place if the environment calls for it, such as
735 // for tracking TCMalloc allocations. This insertion is idempotent, so we 734 // for tracking TCMalloc allocations. This insertion is idempotent, so we
736 // don't mind if there is a race, and we'd prefer not to be in a lock while 735 // don't mind if there is a race, and we'd prefer not to be in a lock while
737 // doing this work. 736 // doing this work.
738 if (kAllowAlternateTimeSourceHandling) 737 if (kAllowAlternateTimeSourceHandling)
739 OptionallyInitializeAlternateTimer(); 738 OptionallyInitializeAlternateTimer();
740 739
741 // Perform the "real" TLS initialization now, and leave it intact through 740 // Perform the "real" TLS initialization now, and leave it intact through
742 // process termination. 741 // process termination.
743 if (!tls_index_.initialized()) { // Testing may have initialized this. 742 if (!tls_index_.initialized()) { // Testing may have initialized this.
744 DCHECK_EQ(status_, UNINITIALIZED); 743 DCHECK_EQ(status_, UNINITIALIZED);
745 tls_index_.Initialize(&ThreadData::OnThreadTermination); 744 tls_index_.Initialize(&ThreadData::OnThreadTermination);
746 if (!tls_index_.initialized()) 745 DCHECK(tls_index_.initialized());
747 return false;
748 } else { 746 } else {
749 // TLS was initialzed for us earlier. 747 // TLS was initialzed for us earlier.
750 DCHECK_EQ(status_, DORMANT_DURING_TESTS); 748 DCHECK_EQ(status_, DORMANT_DURING_TESTS);
751 } 749 }
752 750
753 // Incarnation counter is only significant to testing, as it otherwise will 751 // Incarnation counter is only significant to testing, as it otherwise will
754 // never again change in this process. 752 // never again change in this process.
755 ++incarnation_counter_; 753 ++incarnation_counter_;
756 754
757 // The lock is not critical for setting status_, but it doesn't hurt. It also 755 // The lock is not critical for setting status_, but it doesn't hurt. It also
758 // ensures that if we have a racy initialization, that we'll bail as soon as 756 // ensures that if we have a racy initialization, that we'll bail as soon as
759 // we get the lock earlier in this method. 757 // we get the lock earlier in this method.
760 status_ = kInitialStartupState; 758 status_ = kInitialStartupState;
761 DCHECK(status_ != UNINITIALIZED); 759 DCHECK(status_ != UNINITIALIZED);
762 return true;
763 } 760 }
764 761
765 // static 762 // static
766 bool ThreadData::InitializeAndSetTrackingStatus(Status status) { 763 void ThreadData::InitializeAndSetTrackingStatus(Status status) {
767 DCHECK_GE(status, DEACTIVATED); 764 DCHECK_GE(status, DEACTIVATED);
768 DCHECK_LE(status, PROFILING_ACTIVE); 765 DCHECK_LE(status, PROFILING_ACTIVE);
769 766
770 if (!Initialize()) // No-op if already initialized. 767 Initialize(); // No-op if already initialized.
771 return false; // Not compiled in.
772 768
773 if (status > DEACTIVATED) 769 if (status > DEACTIVATED)
774 status = PROFILING_ACTIVE; 770 status = PROFILING_ACTIVE;
775 status_ = status; 771 status_ = status;
776 return true;
777 } 772 }
778 773
779 // static 774 // static
780 ThreadData::Status ThreadData::status() { 775 ThreadData::Status ThreadData::status() {
781 return status_; 776 return status_;
782 } 777 }
783 778
784 // static 779 // static
785 bool ThreadData::TrackingStatus() { 780 bool ThreadData::TrackingStatus() {
786 return status_ > DEACTIVATED; 781 return status_ > DEACTIVATED;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 // now. 815 // now.
821 CHECK_GT(cleanup_count_, major_threads_shutdown_count); 816 CHECK_GT(cleanup_count_, major_threads_shutdown_count);
822 #endif 817 #endif
823 } 818 }
824 819
825 // static 820 // static
826 void ThreadData::ShutdownSingleThreadedCleanup(bool leak) { 821 void ThreadData::ShutdownSingleThreadedCleanup(bool leak) {
827 // This is only called from test code, where we need to cleanup so that 822 // This is only called from test code, where we need to cleanup so that
828 // additional tests can be run. 823 // additional tests can be run.
829 // We must be single threaded... but be careful anyway. 824 // We must be single threaded... but be careful anyway.
830 if (!InitializeAndSetTrackingStatus(DEACTIVATED)) 825 InitializeAndSetTrackingStatus(DEACTIVATED);
831 return; 826
832 ThreadData* thread_data_list; 827 ThreadData* thread_data_list;
833 { 828 {
834 base::AutoLock lock(*list_lock_.Pointer()); 829 base::AutoLock lock(*list_lock_.Pointer());
835 thread_data_list = all_thread_data_list_head_; 830 thread_data_list = all_thread_data_list_head_;
836 all_thread_data_list_head_ = NULL; 831 all_thread_data_list_head_ = NULL;
837 ++incarnation_counter_; 832 ++incarnation_counter_;
838 // To be clean, break apart the retired worker list (though we leak them). 833 // To be clean, break apart the retired worker list (though we leak them).
839 while (first_retired_worker_) { 834 while (first_retired_worker_) {
840 ThreadData* worker = first_retired_worker_; 835 ThreadData* worker = first_retired_worker_;
841 CHECK_GT(worker->worker_thread_number_, 0); 836 CHECK_GT(worker->worker_thread_number_, 0);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 : process_id(base::GetCurrentProcId()) { 1024 : process_id(base::GetCurrentProcId()) {
1030 #else 1025 #else
1031 : process_id(base::kNullProcessId) { 1026 : process_id(base::kNullProcessId) {
1032 #endif 1027 #endif
1033 } 1028 }
1034 1029
1035 ProcessDataSnapshot::~ProcessDataSnapshot() { 1030 ProcessDataSnapshot::~ProcessDataSnapshot() {
1036 } 1031 }
1037 1032
1038 } // namespace tracked_objects 1033 } // namespace tracked_objects
OLDNEW
« no previous file with comments | « base/tracked_objects.h ('k') | base/tracked_objects_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698