summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-31 07:26:16 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-31 07:26:16 +0000
commit862aa2f012c23229fe307c800c93318f15f32ba9 (patch)
tree668a34e2f25a89fe592a8d1fb39647bc9e08e221 /base
parent86440f533f6efca55ff112c93c6bab8839c797e2 (diff)
downloadchromium_src-862aa2f012c23229fe307c800c93318f15f32ba9.zip
chromium_src-862aa2f012c23229fe307c800c93318f15f32ba9.tar.gz
chromium_src-862aa2f012c23229fe307c800c93318f15f32ba9.tar.bz2
Avoid re-initializing object_tracker
...even if we're asked to do so in repetetive tests. BUG=31334 r=apavlov Review URL: http://codereview.chromium.org/515068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35415 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/tracked_objects.cc4
-rw-r--r--base/tracked_objects.h27
2 files changed, 28 insertions, 3 deletions
diff --git a/base/tracked_objects.cc b/base/tracked_objects.cc
index a51c0da..bc259a2 100644
--- a/base/tracked_objects.cc
+++ b/base/tracked_objects.cc
@@ -18,6 +18,10 @@ namespace tracked_objects {
// static
TLSSlot ThreadData::tls_index_(base::LINKER_INITIALIZED);
+// A global state variable to prevent repeated initialization during tests.
+// static
+AutoTracking::State AutoTracking::state_ = AutoTracking::kNeverBeenRun;
+
//------------------------------------------------------------------------------
// Death data tallies durations when a death takes place.
diff --git a/base/tracked_objects.h b/base/tracked_objects.h
index 4d63997..48e2b5a 100644
--- a/base/tracked_objects.h
+++ b/base/tracked_objects.h
@@ -654,24 +654,45 @@ class ThreadData {
//------------------------------------------------------------------------------
// Provide simple way to to start global tracking, and to tear down tracking
// when done. Note that construction and destruction of this object must be
-// done when running in single threaded mode (before spawning a lot of threads
+// done when running in threaded mode (before spawning a lot of threads
// for construction, and after shutting down all the threads for destruction).
+// To prevent grabbing thread local store resources time and again if someone
+// chooses to try to re-run the browser many times, we maintain global state and
+// only allow the tracking system to be started up at most once, and shutdown
+// at most once. See bug 31344 for an example.
+
class AutoTracking {
public:
- AutoTracking() { ThreadData::StartTracking(true); }
+ AutoTracking() {
+ if (state_ != kNeverBeenRun)
+ return;
+ ThreadData::StartTracking(true);
+ state_ = kRunning;
+ }
~AutoTracking() {
-#ifndef NDEBUG // Don't call these in a Release build: they just waste time.
+#ifndef NDEBUG
+ if (state_ != kRunning)
+ return;
+ // Don't call these in a Release build: they just waste time.
// The following should ONLY be called when in single threaded mode. It is
// unsafe to do this cleanup if other threads are still active.
// It is also very unnecessary, so I'm only doing this in debug to satisfy
// purify (if we need to!).
ThreadData::ShutdownSingleThreadedCleanup();
+ state_ = kTornDownAndStopped;
#endif
}
private:
+ enum State {
+ kNeverBeenRun,
+ kRunning,
+ kTornDownAndStopped,
+ };
+ static State state_;
+
DISALLOW_COPY_AND_ASSIGN(AutoTracking);
};