From 67f92bc3e4a932b3a12693c0517653f08af87a83 Mon Sep 17 00:00:00 2001 From: "fischman@chromium.org" Date: Thu, 26 Jan 2012 01:56:19 +0000 Subject: Convert all remaining explicit LeakyLazyInstanceTraits users to ::Leaky and hide LeakyLazyInstanceTraits in base::internal to discourage cargo-culting new users. BUG=none TEST=none Review URL: http://codereview.chromium.org/9117038 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119173 0039d316-1c4b-4281-b951-d872f2087c98 --- base/lazy_instance.h | 15 +++++++++------ base/mac/scoped_nsexception_enabler.mm | 5 ++--- base/third_party/dmg_fp/dtoa_wrapper.cc | 10 ++++------ base/threading/platform_thread_mac.mm | 5 ++--- base/threading/platform_thread_posix.cc | 3 +-- base/threading/thread_restrictions.cc | 6 +++--- 6 files changed, 21 insertions(+), 23 deletions(-) (limited to 'base') diff --git a/base/lazy_instance.h b/base/lazy_instance.h index 4ed471a..5ddc002 100644 --- a/base/lazy_instance.h +++ b/base/lazy_instance.h @@ -73,11 +73,18 @@ struct DefaultLazyInstanceTraits { } }; +// We pull out some of the functionality into non-templated functions, so we +// can implement the more complicated pieces out of line in the .cc file. +namespace internal { + // Use LazyInstance::Leaky for a less-verbose call-site typedef; e.g.: // base::LazyInstance::Leaky my_leaky_lazy_instance; // instead of: -// base::LazyInstance > my_leaky_lazy_instance; +// base::LazyInstance > +// my_leaky_lazy_instance; // (especially when T is MyLongTypeNameImplClientHolderFactory). +// Only use this internal::-qualified verbose form to extend this traits class +// (depending on its implementation details). template struct LeakyLazyInstanceTraits { static const bool kRegisterOnExit = false; @@ -90,10 +97,6 @@ struct LeakyLazyInstanceTraits { } }; -// We pull out some of the functionality into non-templated functions, so we -// can implement the more complicated pieces out of line in the .cc file. -namespace internal { - // Our AtomicWord doubles as a spinlock, where a value of // kBeingCreatedMarker means the spinlock is being held for creation. static const subtle::AtomicWord kLazyInstanceStateCreating = 1; @@ -124,7 +127,7 @@ class LazyInstance { // Convenience typedef to avoid having to repeat Type for leaky lazy // instances. - typedef LazyInstance > Leaky; + typedef LazyInstance > Leaky; Type& Get() { return *Pointer(); diff --git a/base/mac/scoped_nsexception_enabler.mm b/base/mac/scoped_nsexception_enabler.mm index 52bddb2b..9898789 100644 --- a/base/mac/scoped_nsexception_enabler.mm +++ b/base/mac/scoped_nsexception_enabler.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,7 +9,6 @@ // To make the |g_exceptionsAllowed| declaration readable. using base::LazyInstance; -using base::LeakyLazyInstanceTraits; using base::ThreadLocalBoolean; // When C++ exceptions are disabled, the C++ library defines |try| and @@ -24,7 +23,7 @@ using base::ThreadLocalBoolean; namespace { // Whether to allow NSExceptions to be raised on the current thread. -LazyInstance > +LazyInstance::Leaky g_exceptionsAllowed = LAZY_INSTANCE_INITIALIZER; } // namespace diff --git a/base/third_party/dmg_fp/dtoa_wrapper.cc b/base/third_party/dmg_fp/dtoa_wrapper.cc index 4599df4..c314c59 100644 --- a/base/third_party/dmg_fp/dtoa_wrapper.cc +++ b/base/third_party/dmg_fp/dtoa_wrapper.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -10,17 +10,15 @@ // We need two locks because they're sometimes grabbed at the same time. // A single lock would lead to an attempted recursive grab. -static base::LazyInstance > +static base::LazyInstance::Leaky dtoa_lock_0 = LAZY_INSTANCE_INITIALIZER; -static base::LazyInstance > +static base::LazyInstance::Leaky dtoa_lock_1 = LAZY_INSTANCE_INITIALIZER; /* * This define and the code below is to trigger thread-safe behavior * in dtoa.cc, per this comment from the file: - * + * * #define MULTIPLE_THREADS if the system offers preemptively scheduled * multiple threads. In this case, you must provide (or suitably * #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed diff --git a/base/threading/platform_thread_mac.mm b/base/threading/platform_thread_mac.mm index 422080f..96c6720 100644 --- a/base/threading/platform_thread_mac.mm +++ b/base/threading/platform_thread_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -19,8 +19,7 @@ namespace base { namespace { -LazyInstance, - LeakyLazyInstanceTraits > > +LazyInstance >::Leaky current_thread_name = LAZY_INSTANCE_INITIALIZER; } // namespace diff --git a/base/threading/platform_thread_posix.cc b/base/threading/platform_thread_posix.cc index 27e666a..978b21b 100644 --- a/base/threading/platform_thread_posix.cc +++ b/base/threading/platform_thread_posix.cc @@ -40,8 +40,7 @@ namespace { #if !defined(OS_MACOSX) // Mac name code is in in platform_thread_mac.mm. -LazyInstance, - LeakyLazyInstanceTraits > > +LazyInstance >::Leaky current_thread_name = LAZY_INSTANCE_INITIALIZER; #endif diff --git a/base/threading/thread_restrictions.cc b/base/threading/thread_restrictions.cc index 073349c..b093fb4 100644 --- a/base/threading/thread_restrictions.cc +++ b/base/threading/thread_restrictions.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -15,10 +15,10 @@ namespace base { namespace { -LazyInstance > +LazyInstance::Leaky g_io_disallowed = LAZY_INSTANCE_INITIALIZER; -LazyInstance > +LazyInstance::Leaky g_singleton_disallowed = LAZY_INSTANCE_INITIALIZER; } // anonymous namespace -- cgit v1.1