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

Unified Diff: base/lazy_instance.h

Issue 8366041: Make the placement-new buffer in LazyInstance<Type> aligned. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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
« no previous file with comments | « no previous file | tools/valgrind/memcheck/suppressions.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/lazy_instance.h
===================================================================
--- base/lazy_instance.h (revision 106713)
+++ base/lazy_instance.h (working copy)
@@ -41,6 +41,7 @@
#include "base/atomicops.h"
#include "base/base_export.h"
#include "base/basictypes.h"
+#include "base/logging.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/threading/thread_restrictions.h"
@@ -51,6 +52,8 @@
static const bool kAllowedToAccessOnNonjoinableThread = false;
static Type* New(void* instance) {
+ DCHECK_EQ(reinterpret_cast<uintptr_t>(instance) % sizeof(instance), 0u)
Nico 2011/10/21 16:26:22 do you need this cast?
Timur Iskhodzhanov 2011/10/21 16:40:28 void * ptr; ptr % const -> doesn't compile. Sugge
+ << ": Bad boy, the buffer is not aligned!";
Nico 2011/10/21 16:26:22 Maybe explain why this is important and what to do
Timur Iskhodzhanov 2011/10/21 16:40:28 Why - Done. What to do -> it shouldn't happen unle
// 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();
@@ -186,8 +189,8 @@
base::subtle::Release_Store(&me->state_, STATE_EMPTY);
}
+ Type *instance_;
int8 buf_[sizeof(Type)]; // Preallocate the space for the Type instance.
- Type *instance_;
DISALLOW_COPY_AND_ASSIGN(LazyInstance);
};
« no previous file with comments | « no previous file | tools/valgrind/memcheck/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698