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

Unified Diff: base/lazy_instance_unittest.cc

Issue 3956003: ThreadRestrictions: leak the thread local variable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better impl Created 10 years, 2 months 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
Index: base/lazy_instance_unittest.cc
diff --git a/base/lazy_instance_unittest.cc b/base/lazy_instance_unittest.cc
index d55f66489389a30f99c67ef90e15397633c8db62..17313818ebb064f89d92b26eee3d949a0851aa76 100644
--- a/base/lazy_instance_unittest.cc
+++ b/base/lazy_instance_unittest.cc
@@ -95,3 +95,46 @@ TEST(LazyInstanceTest, ConstructorThreadSafety) {
EXPECT_EQ(1, SlowConstructor::constructed);
}
}
+
+namespace {
+
+// DeleteLogger is an object which sets a flag when it's destroyed.
+// It accepts a bool* and sets the bool to true when the dtor runs.
+class DeleteLogger {
+ public:
+ DeleteLogger() : deleted_(NULL) {}
+ ~DeleteLogger() { *deleted_ = true; }
+
+ void SetDeletedPtr(bool* deleted) {
+ deleted_ = deleted;
+ }
+
+ private:
+ bool* deleted_;
+};
+
+} // anonymous namespace
willchan no longer on Chromium 2010/10/21 20:26:50 I actually don't understand why this whole file is
+
+TEST(LazyInstanceTest, LeakyLazyInstance) {
+ // Check that using a plain LazyInstance causes the dtor to run
+ // when the AtExitManager finishes.
+ bool deleted1 = false;
+ {
+ base::ShadowingAtExitManager shadow;
+ static base::LazyInstance<DeleteLogger> test(base::LINKER_INITIALIZED);
+ test.Get().SetDeletedPtr(&deleted1);
+ }
+ EXPECT_TRUE(deleted1);
+
+ // Check that using a *leaky* LazyInstance makes the dtor not run
+ // when the AtExitManager finishes.
+ bool deleted2 = false;
+ {
+ base::ShadowingAtExitManager shadow;
+ static base::LazyInstance<DeleteLogger,
+ base::LeakyLazyInstanceTraits<DeleteLogger> >
+ test(base::LINKER_INITIALIZED);
+ test.Get().SetDeletedPtr(&deleted2);
+ }
+ EXPECT_FALSE(deleted2);
+}
« no previous file with comments | « base/lazy_instance.cc ('k') | base/thread_restrictions.cc » ('j') | base/thread_restrictions.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698