OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 8 |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 tls_index_.Set(worker_thread_data); | 221 tls_index_.Set(worker_thread_data); |
222 return worker_thread_data; | 222 return worker_thread_data; |
223 } | 223 } |
224 | 224 |
225 // static | 225 // static |
226 void ThreadData::OnThreadTermination(void* thread_data) { | 226 void ThreadData::OnThreadTermination(void* thread_data) { |
227 // We must NOT do any allocations during this callback. There is a chance | 227 // We must NOT do any allocations during this callback. There is a chance |
228 // that the allocator is no longer active on this thread. | 228 // that the allocator is no longer active on this thread. |
229 if (!kTrackAllTaskObjects) | 229 if (!kTrackAllTaskObjects) |
230 return; // Not compiled in. | 230 return; // Not compiled in. |
231 if (!thread_data) | |
232 return; | |
233 reinterpret_cast<ThreadData*>(thread_data)->OnThreadTerminationCleanup(); | 231 reinterpret_cast<ThreadData*>(thread_data)->OnThreadTerminationCleanup(); |
234 } | 232 } |
235 | 233 |
236 void ThreadData::OnThreadTerminationCleanup() { | 234 void ThreadData::OnThreadTerminationCleanup() { |
237 // The list_lock_ was created when we registered the callback, so it won't be | 235 // The list_lock_ was created when we registered the callback, so it won't be |
238 // allocated here despite the lazy reference. | 236 // allocated here despite the lazy reference. |
239 base::AutoLock lock(*list_lock_.Pointer()); | 237 base::AutoLock lock(*list_lock_.Pointer()); |
240 if (incarnation_counter_ != incarnation_count_for_pool_) | 238 if (incarnation_counter_ != incarnation_count_for_pool_) |
241 return; // ThreadData was constructed in an earlier unit test. | 239 return; // ThreadData was constructed in an earlier unit test. |
242 ++cleanup_count_; | 240 ++cleanup_count_; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 } | 516 } |
519 | 517 |
520 // static | 518 // static |
521 void ThreadData::EnsureCleanupWasCalled(int major_threads_shutdown_count) { | 519 void ThreadData::EnsureCleanupWasCalled(int major_threads_shutdown_count) { |
522 base::AutoLock lock(*list_lock_.Pointer()); | 520 base::AutoLock lock(*list_lock_.Pointer()); |
523 if (worker_thread_data_creation_count_ == 0) | 521 if (worker_thread_data_creation_count_ == 0) |
524 return; // We haven't really run much, and couldn't have leaked. | 522 return; // We haven't really run much, and couldn't have leaked. |
525 // Verify that we've at least shutdown/cleanup the major namesd threads. The | 523 // Verify that we've at least shutdown/cleanup the major namesd threads. The |
526 // caller should tell us how many thread shutdowns should have taken place by | 524 // caller should tell us how many thread shutdowns should have taken place by |
527 // now. | 525 // now. |
528 return; // TODO(jar): until this is working on XP, don't run the real test. | |
529 CHECK_GT(cleanup_count_, major_threads_shutdown_count); | 526 CHECK_GT(cleanup_count_, major_threads_shutdown_count); |
530 } | 527 } |
531 | 528 |
532 // static | 529 // static |
533 void ThreadData::ShutdownSingleThreadedCleanup(bool leak) { | 530 void ThreadData::ShutdownSingleThreadedCleanup(bool leak) { |
534 // This is only called from test code, where we need to cleanup so that | 531 // This is only called from test code, where we need to cleanup so that |
535 // additional tests can be run. | 532 // additional tests can be run. |
536 // We must be single threaded... but be careful anyway. | 533 // We must be single threaded... but be careful anyway. |
537 if (!InitializeAndSetTrackingStatus(false)) | 534 if (!InitializeAndSetTrackingStatus(false)) |
538 return; | 535 return; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 | 670 |
674 base::ListValue* DataCollector::ToValue() const { | 671 base::ListValue* DataCollector::ToValue() const { |
675 base::ListValue* list = new base::ListValue; | 672 base::ListValue* list = new base::ListValue; |
676 for (size_t i = 0; i < collection_.size(); ++i) { | 673 for (size_t i = 0; i < collection_.size(); ++i) { |
677 list->Append(collection_[i].ToValue()); | 674 list->Append(collection_[i].ToValue()); |
678 } | 675 } |
679 return list; | 676 return list; |
680 } | 677 } |
681 | 678 |
682 } // namespace tracked_objects | 679 } // namespace tracked_objects |
OLD | NEW |