From 862aa2f012c23229fe307c800c93318f15f32ba9 Mon Sep 17 00:00:00 2001 From: "jar@chromium.org" Date: Thu, 31 Dec 2009 07:26:16 +0000 Subject: 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 --- base/tracked_objects.cc | 4 ++++ base/tracked_objects.h | 27 ++++++++++++++++++++++++--- 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); }; -- cgit v1.1