diff options
author | jar@google.com <jar@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-30 20:50:01 +0000 |
---|---|---|
committer | jar@google.com <jar@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-30 20:50:01 +0000 |
commit | 022614ef938eb2832aa5a4ba09ee0220b4837dec (patch) | |
tree | 6144c1b8b48ba889c03fdacd4e647e2a900c4190 | |
parent | 7998c34f7003cc3da62278fa82068b70fe940d5c (diff) | |
download | chromium_src-022614ef938eb2832aa5a4ba09ee0220b4837dec.zip chromium_src-022614ef938eb2832aa5a4ba09ee0220b4837dec.tar.gz chromium_src-022614ef938eb2832aa5a4ba09ee0220b4837dec.tar.bz2 |
Provide and use auto startup/teardown for tracked objects
Avoid races with message loop teardown
r=nsylvain
Review URL: http://codereview.chromium.org/17023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7503 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/tracked_objects.h | 38 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 30 |
2 files changed, 41 insertions, 27 deletions
diff --git a/base/tracked_objects.h b/base/tracked_objects.h index 638ea24..4a86841 100644 --- a/base/tracked_objects.h +++ b/base/tracked_objects.h @@ -39,7 +39,7 @@ class BirthOnThread { // allowed to access birth_count_ (which changes over time). const ThreadData* birth_thread_; // The thread this birth took place on. - DISALLOW_EVIL_CONSTRUCTORS(BirthOnThread); + DISALLOW_COPY_AND_ASSIGN(BirthOnThread); }; //------------------------------------------------------------------------------ @@ -62,7 +62,7 @@ class Births: public BirthOnThread { // The number of births on this thread for our location_. int birth_count_; - DISALLOW_EVIL_CONSTRUCTORS(Births); + DISALLOW_COPY_AND_ASSIGN(Births); }; //------------------------------------------------------------------------------ @@ -183,7 +183,7 @@ class DataCollector { Lock accumulation_lock_; // Protects access during accumulation phase. - DISALLOW_EVIL_CONSTRUCTORS(DataCollector); + DISALLOW_COPY_AND_ASSIGN(DataCollector); }; //------------------------------------------------------------------------------ @@ -209,7 +209,7 @@ class Aggregation: public DeathData { DeathData death_data_; std::map<const ThreadData*, int> death_threads_; - DISALLOW_EVIL_CONSTRUCTORS(Aggregation); + DISALLOW_COPY_AND_ASSIGN(Aggregation); }; //------------------------------------------------------------------------------ @@ -428,7 +428,7 @@ class ThreadData { // Make sure enough tasks are called before completion is signaled. ThreadSafeDownCounter* counter_; - DISALLOW_EVIL_CONSTRUCTORS(RunTheStatic); + DISALLOW_COPY_AND_ASSIGN(RunTheStatic); }; #endif @@ -480,9 +480,35 @@ class ThreadData { // data, but that is considered acceptable errors (mis-information). Lock lock_; - DISALLOW_EVIL_CONSTRUCTORS(ThreadData); + DISALLOW_COPY_AND_ASSIGN(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 +// for construction, and after shutting down all the threads for destruction). + +class AutoTracking { + public: + AutoTracking() { ThreadData::StartTracking(true); } + + ~AutoTracking() { +#ifndef NDEBUG // 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(); +#endif + } + + private: + DISALLOW_COPY_AND_ASSIGN(AutoTracking); +}; + + } // namespace tracked_objects #endif // BASE_TRACKED_OBJECTS_H_ diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 4bea540..21be5b6 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -7,9 +7,9 @@ #include "base/command_line.h" #include "sandbox/src/sandbox.h" -// TODO(port): several win-only methods have been pulled out of this, but +// TODO(port): several win-only methods have been pulled out of this, but // BrowserMain() as a whole needs to be broken apart so that it's usable by -// other platforms. For now, it's just a stub. This is a serious work in +// other platforms. For now, it's just a stub. This is a serious work in // progress and should not be taken as an indication of a real refactoring. #if defined(OS_WIN) @@ -150,6 +150,13 @@ int BrowserMain(CommandLine &parsed_command_line, // TODO(beng, brettw): someday, break this out into sub functions with well // defined roles (e.g. pre/post-profile startup, etc). +#ifdef TRACK_ALL_TASK_OBJECTS + // Start tracking the creation and deletion of Task instance. + // This construction MUST be done before main_message_loop, so that it is + // destroyed after the main_message_loop. + tracked_objects::AutoTracking tracking_objects; +#endif + MessageLoop main_message_loop(MessageLoop::TYPE_UI); // Initialize the SystemMonitor @@ -264,12 +271,6 @@ int BrowserMain(CommandLine &parsed_command_line, // Initialize histogram statistics gathering system. StatisticsRecorder statistics; - // Start tracking the creation and deletion of Task instances - bool tracking_objects = false; -#ifdef TRACK_ALL_TASK_OBJECTS - tracking_objects = tracked_objects::ThreadData::StartTracking(true); -#endif - // Initialize the shared instance of user data manager. UserDataManager::Create(); @@ -487,21 +488,8 @@ int BrowserMain(CommandLine &parsed_command_line, // browser_shutdown takes care of deleting browser_process, so we need to // release it. browser_process.release(); - browser_shutdown::Shutdown(); - // The following teardown code will pacify Purify, but is not necessary for - // shutdown. Only list methods here that have no significant side effects - // and can be run in single threaded mode before terminating. -#ifndef NDEBUG // 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 (tracking_objects) - tracked_objects::ThreadData::ShutdownSingleThreadedCleanup(); -#endif // NDEBUG - return result_code; } |