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

Unified Diff: base/lazy_instance.h

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
« no previous file with comments | « no previous file | base/lazy_instance.cc » ('j') | base/lazy_instance_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/lazy_instance.h
diff --git a/base/lazy_instance.h b/base/lazy_instance.h
index 52a51248f38543e33970bdbec8aafacddfb777e9..ebf1e73024cb5d2ba1455fe8161d89b06a7cc39e 100644
--- a/base/lazy_instance.h
+++ b/base/lazy_instance.h
@@ -55,6 +55,22 @@ struct DefaultLazyInstanceTraits {
}
};
+template <typename Type>
+struct LeakyLazyInstanceTraits {
+ static Type* New(void* instance) {
+ return DefaultLazyInstanceTraits<Type>::New(instance);
+ }
+ // Rather than define an empty Delete function, we make Delete itself
+ // a null pointer. This allows us to completely sidestep registering
+ // this object with an AtExitManager, which allows you to use
+ // LeakyLazyInstanceTraits in contexts where you don't have an
+ // AtExitManager.
+ static void (*Delete)(void* instance);
+};
+
+template <typename Type>
+void (*LeakyLazyInstanceTraits<Type>::Delete)(void* instance) = NULL;
+
// We pull out some of the functionality into a non-templated base, so that we
// can implement the more complicated pieces out of line in the .cc file.
class LazyInstanceHelper {
« no previous file with comments | « no previous file | base/lazy_instance.cc » ('j') | base/lazy_instance_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698