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

Unified Diff: src/lazy-instance.h

Issue 9702114: MIPS: Ensure proper alignment of LazyInstance objects. (Closed)
Patch Set: rebased on r11230 Created 8 years, 8 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/lazy-instance.h
diff --git a/src/lazy-instance.h b/src/lazy-instance.h
index 4beb55c0a291b05cf91bde23ffd8af03f1be9f6a..d0893e560470ee345adbd1af45cd295b998fc610 100644
--- a/src/lazy-instance.h
+++ b/src/lazy-instance.h
@@ -107,9 +107,17 @@ struct LeakyInstanceTrait {
// Traits that define how an instance is allocated and accessed.
+// TODO(kalmard): __alignof__ is only defined for GCC > 4.2. Fix alignment issue
+// on MIPS with other compilers.
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2))
+#define LAZY_ALIGN(x) __attribute__((aligned(__alignof__(x))))
+#else
+#define LAZY_ALIGN(x)
+#endif
+
template <typename T>
struct StaticallyAllocatedInstanceTrait {
- typedef char StorageType[sizeof(T)];
+ typedef char StorageType[sizeof(T)] LAZY_ALIGN(T);
static T* MutableInstance(StorageType* storage) {
return reinterpret_cast<T*>(storage);
@@ -121,6 +129,8 @@ struct StaticallyAllocatedInstanceTrait {
}
};
+#undef LAZY_ALIGN
+
template <typename T>
struct DynamicallyAllocatedInstanceTrait {
@@ -208,7 +218,8 @@ struct LazyInstanceImpl {
mutable OnceType once_;
// Note that the previous field, OnceType, is an AtomicWord which guarantees
- // the correct alignment of the storage field below.
+ // 4-byte alignment of the storage field below. If compiling with GCC (>4.2),
+ // the LAZY_ALIGN macro above will guarantee correctness for any alignment.
mutable StorageType storage_;
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698