diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-12 21:25:38 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-12 21:25:38 +0000 |
commit | 82e8e2b5b879cd414e48e6418fb1a693093866e2 (patch) | |
tree | 513b4c2186f8be29e2d8a7d56e76a75d96dbf437 /base/lazy_instance.h | |
parent | 48a5faa6500b6c6055348abf1540cbb06c721f33 (diff) | |
download | chromium_src-82e8e2b5b879cd414e48e6418fb1a693093866e2.zip chromium_src-82e8e2b5b879cd414e48e6418fb1a693093866e2.tar.gz chromium_src-82e8e2b5b879cd414e48e6418fb1a693093866e2.tar.bz2 |
Disallow Singleton and LazyInstance on non-joinable threads.
Fix all known instances or explicitly allow them. Usually the fix involves switching from Default traits to Lazy traits.
BUG=61753
TEST=none
Review URL: http://codereview.chromium.org/4635012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65996 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/lazy_instance.h')
-rw-r--r-- | base/lazy_instance.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/base/lazy_instance.h b/base/lazy_instance.h index ebf1e73..27cb784 100644 --- a/base/lazy_instance.h +++ b/base/lazy_instance.h @@ -36,14 +36,18 @@ #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 +61,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 +118,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()) { |