| Index: base/lazy_instance.h
|
| diff --git a/base/lazy_instance.h b/base/lazy_instance.h
|
| index ebf1e73024cb5d2ba1455fe8161d89b06a7cc39e..f8d59873f297484a120ebf927fcd2bfeb48bdb79 100644
|
| --- a/base/lazy_instance.h
|
| +++ b/base/lazy_instance.h
|
| @@ -36,14 +36,19 @@
|
| #define BASE_LAZY_INSTANCE_H_
|
| #pragma once
|
|
|
| +#include <new> // For placement new.
|
| +
|
| #include "base/atomicops.h"
|
| #include "base/basictypes.h"
|
| #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
|
| +#include "base/thread_restrictions.h"
|
|
|
| namespace base {
|
|
|
| template <typename Type>
|
| struct DefaultLazyInstanceTraits {
|
| + static const bool kAllowedToAccessOnNonjoinableThread = false;
|
| +
|
| static Type* New(void* instance) {
|
| // Use placement new to initialize our instance in our preallocated space.
|
| // The parenthesis is very important here to force POD type initialization.
|
| @@ -57,6 +62,8 @@ struct DefaultLazyInstanceTraits {
|
|
|
| template <typename Type>
|
| struct LeakyLazyInstanceTraits {
|
| + static const bool kAllowedToAccessOnNonjoinableThread = true;
|
| +
|
| static Type* New(void* instance) {
|
| return DefaultLazyInstanceTraits<Type>::New(instance);
|
| }
|
| @@ -112,6 +119,9 @@ class LazyInstance : public LazyInstanceHelper {
|
| }
|
|
|
| Type* Pointer() {
|
| + if (!Traits::kAllowedToAccessOnNonjoinableThread)
|
| + base::ThreadRestrictions::AssertSingletonAllowed();
|
| +
|
| // We will hopefully have fast access when the instance is already created.
|
| if ((base::subtle::NoBarrier_Load(&state_) != STATE_CREATED) &&
|
| NeedsInstance()) {
|
| @@ -126,7 +136,6 @@ class LazyInstance : public LazyInstanceHelper {
|
| // and CompleteInstance(...) happens before "return instance_" below.
|
| // See the corresponding HAPPENS_BEFORE in CompleteInstance(...).
|
| ANNOTATE_HAPPENS_AFTER(&state_);
|
| -
|
| return instance_;
|
| }
|
|
|
|
|