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 <math.h> | 7 #include <math.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/debug/leak_annotations.h" | |
| 11 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/process_util.h" | 14 #include "base/process_util.h" |
| 14 #include "base/profiler/alternate_timer.h" | 15 #include "base/profiler/alternate_timer.h" |
| 15 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 16 #include "base/third_party/valgrind/memcheck.h" | 17 #include "base/third_party/valgrind/memcheck.h" |
| 17 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
| 18 #include "base/port.h" | 19 #include "base/port.h" |
| 19 | 20 |
| 20 using base::TimeDelta; | 21 using base::TimeDelta; |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 771 if (worker_thread_data_creation_count_ == 0) | 772 if (worker_thread_data_creation_count_ == 0) |
| 772 return; // We haven't really run much, and couldn't have leaked. | 773 return; // We haven't really run much, and couldn't have leaked. |
| 773 // Verify that we've at least shutdown/cleanup the major namesd threads. The | 774 // Verify that we've at least shutdown/cleanup the major namesd threads. The |
| 774 // caller should tell us how many thread shutdowns should have taken place by | 775 // caller should tell us how many thread shutdowns should have taken place by |
| 775 // now. | 776 // now. |
| 776 return; // TODO(jar): until this is working on XP, don't run the real test. | 777 return; // TODO(jar): until this is working on XP, don't run the real test. |
| 777 CHECK_GT(cleanup_count_, major_threads_shutdown_count); | 778 CHECK_GT(cleanup_count_, major_threads_shutdown_count); |
| 778 } | 779 } |
| 779 | 780 |
| 780 // static | 781 // static |
| 781 void ThreadData::ShutdownSingleThreadedCleanup(bool leak) { | 782 void ThreadData::ShutdownSingleThreadedCleanup(bool leak) { |
|
jar (doing other things)
2013/06/08 00:24:15
This function is *only* called during cleanup, whi
| |
| 782 // This is only called from test code, where we need to cleanup so that | 783 // This is only called from test code, where we need to cleanup so that |
| 783 // additional tests can be run. | 784 // additional tests can be run. |
| 784 // We must be single threaded... but be careful anyway. | 785 // We must be single threaded... but be careful anyway. |
| 785 if (!InitializeAndSetTrackingStatus(DEACTIVATED)) | 786 if (!InitializeAndSetTrackingStatus(DEACTIVATED)) |
| 786 return; | 787 return; |
| 787 ThreadData* thread_data_list; | 788 ThreadData* thread_data_list; |
| 788 { | 789 { |
| 789 base::AutoLock lock(*list_lock_.Pointer()); | 790 base::AutoLock lock(*list_lock_.Pointer()); |
| 790 thread_data_list = all_thread_data_list_head_; | 791 thread_data_list = all_thread_data_list_head_; |
| 791 all_thread_data_list_head_ = NULL; | 792 all_thread_data_list_head_ = NULL; |
| 792 ++incarnation_counter_; | 793 ++incarnation_counter_; |
| 793 // To be clean, break apart the retired worker list (though we leak them). | 794 // To be clean, break apart the retired worker list (though we leak them). |
| 794 while (first_retired_worker_) { | 795 while (first_retired_worker_) { |
| 795 ThreadData* worker = first_retired_worker_; | 796 ThreadData* worker = first_retired_worker_; |
| 796 CHECK_GT(worker->worker_thread_number_, 0); | 797 CHECK_GT(worker->worker_thread_number_, 0); |
| 797 first_retired_worker_ = worker->next_retired_worker_; | 798 first_retired_worker_ = worker->next_retired_worker_; |
| 798 worker->next_retired_worker_ = NULL; | 799 worker->next_retired_worker_ = NULL; |
| 799 } | 800 } |
| 800 } | 801 } |
| 801 | 802 |
| 802 // Put most global static back in pristine shape. | 803 // Put most global static back in pristine shape. |
| 803 worker_thread_data_creation_count_ = 0; | 804 worker_thread_data_creation_count_ = 0; |
| 804 cleanup_count_ = 0; | 805 cleanup_count_ = 0; |
| 805 tls_index_.Set(NULL); | 806 tls_index_.Set(NULL); |
| 806 status_ = DORMANT_DURING_TESTS; // Almost UNINITIALIZED. | 807 status_ = DORMANT_DURING_TESTS; // Almost UNINITIALIZED. |
| 807 | 808 |
| 808 // To avoid any chance of racing in unit tests, which is the only place we | 809 // To avoid any chance of racing in unit tests, which is the only place we |
| 809 // call this function, we may sometimes leak all the data structures we | 810 // call this function, we may sometimes leak all the data structures we |
| 810 // recovered, as they may still be in use on threads from prior tests! | 811 // recovered, as they may still be in use on threads from prior tests! |
| 811 if (leak) | 812 if (leak) { |
| 813 ThreadData* thread_data = thread_data_list; | |
| 814 while (thread_data) { | |
| 815 ANNOTATE_LEAKING_OBJECT_PTR(thread_data); | |
| 816 thread_data = thread_data->next(); | |
| 817 } | |
| 812 return; | 818 return; |
| 819 } | |
| 813 | 820 |
| 814 // When we want to cleanup (on a single thread), here is what we do. | 821 // When we want to cleanup (on a single thread), here is what we do. |
| 815 | 822 |
| 816 // Do actual recursive delete in all ThreadData instances. | 823 // Do actual recursive delete in all ThreadData instances. |
| 817 while (thread_data_list) { | 824 while (thread_data_list) { |
| 818 ThreadData* next_thread_data = thread_data_list; | 825 ThreadData* next_thread_data = thread_data_list; |
| 819 thread_data_list = thread_data_list->next(); | 826 thread_data_list = thread_data_list->next(); |
| 820 | 827 |
| 821 for (BirthMap::iterator it = next_thread_data->birth_map_.begin(); | 828 for (BirthMap::iterator it = next_thread_data->birth_map_.begin(); |
| 822 next_thread_data->birth_map_.end() != it; ++it) | 829 next_thread_data->birth_map_.end() != it; ++it) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 863 : process_id(base::GetCurrentProcId()) { | 870 : process_id(base::GetCurrentProcId()) { |
| 864 #else | 871 #else |
| 865 : process_id(0) { | 872 : process_id(0) { |
| 866 #endif | 873 #endif |
| 867 } | 874 } |
| 868 | 875 |
| 869 ProcessDataSnapshot::~ProcessDataSnapshot() { | 876 ProcessDataSnapshot::~ProcessDataSnapshot() { |
| 870 } | 877 } |
| 871 | 878 |
| 872 } // namespace tracked_objects | 879 } // namespace tracked_objects |
| OLD | NEW |