diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-19 09:11:39 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-19 09:11:39 +0000 |
commit | 4ea927b886af2654b5a193278c0bfb6c25b56fc7 (patch) | |
tree | 81c0a1916e2b683b687ed6538386fcdbc9261c11 /base/lazy_instance.cc | |
parent | d10852ddcea9285a2808a1fa0caeddf4c5e221e0 (diff) | |
download | chromium_src-4ea927b886af2654b5a193278c0bfb6c25b56fc7.zip chromium_src-4ea927b886af2654b5a193278c0bfb6c25b56fc7.tar.gz chromium_src-4ea927b886af2654b5a193278c0bfb6c25b56fc7.tar.bz2 |
Isolate tests by running AtExit callbacks between them.
For now, this is only for base_unittests. The plan is to enable
it for all unit tests. This should finally fix mysterious
problems cause by Singletons surviving after one test etc.
This change also adapts LazyInstance so that it can be reused
after being destroyed. It is used very frequently, for example
each time a MessageLoop is used. It is also worth noting that
we had some problems in the past related to the MessageLoop
being destroyed and re-instantiated in the same test executable.
This patch should also fix that.
TEST=none
BUG=12710
Review URL: http://codereview.chromium.org/372057
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32507 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/lazy_instance.cc')
-rw-r--r-- | base/lazy_instance.cc | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/base/lazy_instance.cc b/base/lazy_instance.cc index 388622a..9923253 100644 --- a/base/lazy_instance.cc +++ b/base/lazy_instance.cc @@ -27,7 +27,14 @@ void LazyInstanceHelper::EnsureInstance(void* instance, // Instance is created, go from CREATING to CREATED. base::subtle::Release_Store(&state_, STATE_CREATED); - // Register the destructor callback with AtExitManager. + + // Allow reusing the LazyInstance (reset it to the initial state). This + // makes possible calling all AtExit callbacks between tests. Assumes that + // no other threads execute when AtExit callbacks are processed. + base::AtExitManager::RegisterCallback(&LazyInstanceHelper::ResetState, + this); + + // Make sure that the lazily instantiated object will get destroyed at exit. base::AtExitManager::RegisterCallback(dtor, instance); } else { // It's either in the process of being created, or already created. Spin. @@ -36,4 +43,9 @@ void LazyInstanceHelper::EnsureInstance(void* instance, } } +// static +void LazyInstanceHelper::ResetState(void* helper) { + reinterpret_cast<LazyInstanceHelper*>(helper)->state_ = STATE_EMPTY; +} + } // namespace base |