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 /base/tracked_objects.h | |
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
Diffstat (limited to 'base/tracked_objects.h')
-rw-r--r-- | base/tracked_objects.h | 38 |
1 files changed, 32 insertions, 6 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_ |