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

Unified Diff: base/lazy_instance.h

Issue 5682008: Make members of Singleton<T> private and only visible to the singleton type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 10 years 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.h
diff --git a/base/lazy_instance.h b/base/lazy_instance.h
index f8d59873f297484a120ebf927fcd2bfeb48bdb79..61f26a34653458aebf54e5e55e0864e5dac22504 100644
--- a/base/lazy_instance.h
+++ b/base/lazy_instance.h
@@ -127,7 +127,8 @@ class LazyInstance : public LazyInstanceHelper {
NeedsInstance()) {
// Create the instance in the space provided by |buf_|.
instance_ = Traits::New(buf_);
- CompleteInstance(instance_, Traits::Delete);
+ if (Traits::Delete != NULL) // Will be null for LeakyLazyInstannceTraits
M-A Ruel 2010/12/13 17:30:51 LeakyLazyInstanceTraits
+ CompleteInstance(this, OnExit);
}
// This annotation helps race detectors recognize correct lock-less
@@ -140,6 +141,17 @@ class LazyInstance : public LazyInstanceHelper {
}
private:
+ // Adapter function for use with AtExit. This should be called single
+ // threaded, so don't use atomic operations.
+ // Calling OnExit while the instance is in use by other threads is a mistake.
+ static void OnExit(void* lazy_instance) {
+ LazyInstance<Type, Traits>* me =
+ reinterpret_cast<LazyInstance<Type, Traits>*>(lazy_instance);
+ Traits::Delete(me->instance_);
+ me->instance_ = NULL;
+ base::subtle::Release_Store(&me->state_, STATE_EMPTY);
+ }
+
int8 buf_[sizeof(Type)]; // Preallocate the space for the Type instance.
Type *instance_;

Powered by Google App Engine
This is Rietveld 408576698