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

Side by Side Diff: base/tracked_objects.cc

Issue 8570007: Reduce race potential for lazy testing initialization of profiler (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 | « no previous file | tools/valgrind/tsan/suppressions.txt » ('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 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 it->second.Clear(); 576 it->second.Clear();
577 for (BirthMap::iterator it = birth_map_.begin(); 577 for (BirthMap::iterator it = birth_map_.begin();
578 it != birth_map_.end(); ++it) 578 it != birth_map_.end(); ++it)
579 it->second->Clear(); 579 it->second->Clear();
580 } 580 }
581 581
582 bool ThreadData::Initialize() { 582 bool ThreadData::Initialize() {
583 if (!kTrackAllTaskObjects) 583 if (!kTrackAllTaskObjects)
584 return false; // Not compiled in. 584 return false; // Not compiled in.
585 if (status_ != UNINITIALIZED) 585 if (status_ != UNINITIALIZED)
586 return true; 586 return true; // Someone else did the initialization.
587 // Initialize all leaking constants that are difficult to toggle in and out 587 // Due to racy lazy initialization in tests, we'll need to recheck status_
588 // of existance. 588 // after we acquire the lock.
589 // First call must be made when single threaded at startup. 589
590 // Ensure that we don't double initialize tls. We are called when single
591 // threaded in the product, but some tests may be racy and lazy about our
592 // initialization.
593 base::AutoLock lock(*list_lock_.Pointer());
594 if (status_ != UNINITIALIZED)
595 return true; // Someone raced in here and beat us.
596
590 // Perform the "real" TLS initialization now, and leave it intact through 597 // Perform the "real" TLS initialization now, and leave it intact through
591 // process termination. 598 // process termination.
592 if (!tls_index_.initialized()) // Testing may have initialized this. 599 if (!tls_index_.initialized()) { // Testing may have initialized this.
593 tls_index_.Initialize(&ThreadData::OnThreadTermination); 600 tls_index_.Initialize(&ThreadData::OnThreadTermination);
594 DCHECK(tls_index_.initialized()); 601 if (!tls_index_.initialized())
602 return false;
603 }
604
605 // Incarnation counter is only significant to testing, as it otherwise will
606 // never again change in this process.
607 ++incarnation_counter_;
608
609 // The lock is not critical for setting status_, but it doesn't hurt. It also
610 // ensures that if we have a racy initialization, that we'll bail as soon as
611 // we get the lock earlier in this method.
595 status_ = kInitialStartupState; 612 status_ = kInitialStartupState;
596 613 DCHECK(status_ != UNINITIALIZED);
597 base::AutoLock lock(*list_lock_.Pointer());
598 ++incarnation_counter_;
599 return true; 614 return true;
600 } 615 }
601 616
602 // static 617 // static
603 bool ThreadData::InitializeAndSetTrackingStatus(bool status) { 618 bool ThreadData::InitializeAndSetTrackingStatus(bool status) {
604 if (!Initialize()) // No-op if already initialized. 619 if (!Initialize()) // No-op if already initialized.
605 return false; // Not compiled in. 620 return false; // Not compiled in.
606 621
607 status_ = status ? ACTIVE : DEACTIVATED; 622 status_ = status ? ACTIVE : DEACTIVATED;
608 return true; 623 return true;
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 (combined_selectors_ & BIRTH_THREAD) ? "*" : 1268 (combined_selectors_ & BIRTH_THREAD) ? "*" :
1254 sample.birth().birth_thread()->thread_name().c_str(), 1269 sample.birth().birth_thread()->thread_name().c_str(),
1255 (combined_selectors_ & DEATH_THREAD) ? "*" : 1270 (combined_selectors_ & DEATH_THREAD) ? "*" :
1256 sample.DeathThreadName().c_str()); 1271 sample.DeathThreadName().c_str());
1257 sample.birth().location().Write(!(combined_selectors_ & BIRTH_FILE), 1272 sample.birth().location().Write(!(combined_selectors_ & BIRTH_FILE),
1258 !(combined_selectors_ & BIRTH_FUNCTION), 1273 !(combined_selectors_ & BIRTH_FUNCTION),
1259 output); 1274 output);
1260 } 1275 }
1261 1276
1262 } // namespace tracked_objects 1277 } // namespace tracked_objects
OLDNEW
« no previous file with comments | « no previous file | tools/valgrind/tsan/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698