Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2313)

Unified Diff: base/lazy_instance.cc

Issue 372057: Isolate tests by running AtExit callbacks between them. (Closed)
Patch Set: fix Linux hang Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/lazy_instance.h ('k') | base/lazy_instance_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/lazy_instance.cc
diff --git a/base/lazy_instance.cc b/base/lazy_instance.cc
index 388622ae83ebf6a11c0a757f1e57c8a6c87c2aef..992325339cfcbabf3babf92dee3488cd55c2f862 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
« no previous file with comments | « base/lazy_instance.h ('k') | base/lazy_instance_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698