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

Side by Side Diff: base/tracked_objects.cc

Issue 8432003: Reduce leaking in object tracking tests (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
« 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) 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 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 } 535 }
536 536
537 // static 537 // static
538 TrackedTime ThreadData::Now() { 538 TrackedTime ThreadData::Now() {
539 if (kTrackAllTaskObjects && tracking_status()) 539 if (kTrackAllTaskObjects && tracking_status())
540 return TrackedTime::Now(); 540 return TrackedTime::Now();
541 return TrackedTime(); // Super fast when disabled, or not compiled. 541 return TrackedTime(); // Super fast when disabled, or not compiled.
542 } 542 }
543 543
544 // static 544 // static
545 void ThreadData::ShutdownSingleThreadedCleanup() { 545 void ThreadData::ShutdownSingleThreadedCleanup(bool leak) {
546 // This is only called from test code, where we need to cleanup so that 546 // This is only called from test code, where we need to cleanup so that
547 // additional tests can be run. 547 // additional tests can be run.
548 // We must be single threaded... but be careful anyway. 548 // We must be single threaded... but be careful anyway.
549 if (!InitializeAndSetTrackingStatus(false)) 549 if (!InitializeAndSetTrackingStatus(false))
550 return; 550 return;
551 ThreadData* thread_data_list; 551 ThreadData* thread_data_list;
552 ThreadDataPool* final_pool; 552 ThreadDataPool* final_pool;
553 { 553 {
554 base::AutoLock lock(*list_lock_); 554 base::AutoLock lock(*list_lock_);
555 thread_data_list = all_thread_data_list_head_; 555 thread_data_list = all_thread_data_list_head_;
556 all_thread_data_list_head_ = NULL; 556 all_thread_data_list_head_ = NULL;
557 final_pool = unregistered_thread_data_pool_; 557 final_pool = unregistered_thread_data_pool_;
558 unregistered_thread_data_pool_ = NULL; 558 unregistered_thread_data_pool_ = NULL;
559 } 559 }
560 560
561 // Put most global static back in pristine shape. 561 // Put most global static back in pristine shape.
562 thread_number_counter_ = 0; 562 thread_number_counter_ = 0;
563 tls_index_.Set(NULL); 563 tls_index_.Set(NULL);
564 status_ = UNINITIALIZED; 564 status_ = UNINITIALIZED;
565 565
566 // To avoid any chance of racing in unit tests, which is the only place we 566 // To avoid any chance of racing in unit tests, which is the only place we
567 // call this function, we will leak all the data structures we recovered. 567 // call this function, we may sometimes leak all the data structures we
568 // These structures could plausibly be used by other threads in earlier tests 568 // recovered, as they may still be in use on threads from prior tests!
569 // that are still running. 569 if (leak)
570 return; 570 return;
571 571
572 // If we wanted to cleanup (on a single thread), here is what we would do. 572 // When we want to cleanup (on a single thread), here is what we do.
573 573
574 if (final_pool) { 574 if (final_pool) {
575 // The thread_data_list contains *all* the instances, and we'll use it to 575 // The thread_data_list contains *all* the instances, and we'll use it to
576 // delete them. This pool has pointers to some instances, and we just 576 // delete them. This pool has pointers to some instances, and we just
577 // have to drop those pointers (and not do the deletes here). 577 // have to drop those pointers (and not do the deletes here).
578 while (!final_pool->empty()) 578 while (!final_pool->empty())
579 final_pool->pop(); 579 final_pool->pop();
580 delete final_pool; 580 delete final_pool;
581 } 581 }
582 582
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 (combined_selectors_ & BIRTH_THREAD) ? "*" : 1135 (combined_selectors_ & BIRTH_THREAD) ? "*" :
1136 sample.birth().birth_thread()->thread_name().c_str(), 1136 sample.birth().birth_thread()->thread_name().c_str(),
1137 (combined_selectors_ & DEATH_THREAD) ? "*" : 1137 (combined_selectors_ & DEATH_THREAD) ? "*" :
1138 sample.DeathThreadName().c_str()); 1138 sample.DeathThreadName().c_str());
1139 sample.birth().location().Write(!(combined_selectors_ & BIRTH_FILE), 1139 sample.birth().location().Write(!(combined_selectors_ & BIRTH_FILE),
1140 !(combined_selectors_ & BIRTH_FUNCTION), 1140 !(combined_selectors_ & BIRTH_FUNCTION),
1141 output); 1141 output);
1142 } 1142 }
1143 1143
1144 } // namespace tracked_objects 1144 } // 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