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

Unified Diff: base/lazy_instance.h

Issue 2932053002: Use C++11 alignment primitives (Closed)
Patch Set: Put back ALIGNAS Created 3 years, 6 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
Index: base/lazy_instance.h
diff --git a/base/lazy_instance.h b/base/lazy_instance.h
index 070e436d1f0c5a74534ba8fb1a8535a29db789e0..20a2336c0e4facee197381488e78064cd5b1610a 100644
--- a/base/lazy_instance.h
+++ b/base/lazy_instance.h
@@ -36,12 +36,12 @@
#define BASE_LAZY_INSTANCE_H_
#include <new> // For placement new.
+#include <type_traits>
#include "base/atomicops.h"
#include "base/base_export.h"
#include "base/debug/leak_annotations.h"
#include "base/logging.h"
-#include "base/memory/aligned_memory.h"
#include "base/threading/thread_restrictions.h"
// LazyInstance uses its own struct initializer-list style static
@@ -55,7 +55,7 @@ namespace base {
template <typename Type>
struct LazyInstanceTraitsBase {
static Type* New(void* instance) {
- DCHECK_EQ(reinterpret_cast<uintptr_t>(instance) & (ALIGNOF(Type) - 1), 0u);
+ DCHECK_EQ(reinterpret_cast<uintptr_t>(instance) & (alignof(Type) - 1), 0u);
// Use placement new to initialize our instance in our preallocated space.
// The parenthesis is very important here to force POD type initialization.
return new (instance) Type();
@@ -179,8 +179,7 @@ class LazyInstance {
if (!(value & kLazyInstanceCreatedMask) &&
internal::NeedsLazyInstance(&private_instance_)) {
// Create the instance in the space provided by |private_buf_|.
- value = reinterpret_cast<subtle::AtomicWord>(
- Traits::New(private_buf_.void_data()));
+ value = reinterpret_cast<subtle::AtomicWord>(Traits::New(&private_buf_));
internal::CompleteLazyInstance(&private_instance_, value, this,
Traits::kRegisterOnExit ? OnExit : NULL);
}
@@ -192,7 +191,7 @@ class LazyInstance {
case 0:
return p == NULL;
case internal::kLazyInstanceStateCreating:
- return static_cast<void*>(p) == private_buf_.void_data();
+ return static_cast<void*>(p) == &private_buf_;
default:
return p == instance();
}
@@ -204,7 +203,7 @@ class LazyInstance {
subtle::AtomicWord private_instance_;
// Preallocated space for the Type instance.
- base::AlignedMemory<sizeof(Type), ALIGNOF(Type)> private_buf_;
+ typename std::aligned_storage<sizeof(Type), alignof(Type)>::type private_buf_;
private:
Type* instance() {

Powered by Google App Engine
This is Rietveld 408576698