summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2012-08-10 12:48:57 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-08-10 12:48:57 -0700
commita0a2f0c6fa125ca3594282f6fdb0e40d8adcbf8b (patch)
tree549fd7fbd3bd45849de5fa622ab6a3a61c7537de
parente20b4bd98d879307e535cec7d6c8ac670acfaa79 (diff)
parent1c684ed1b5ac92ae473db5718627405367eb1766 (diff)
downloadexternal_chromium-a0a2f0c6fa125ca3594282f6fdb0e40d8adcbf8b.zip
external_chromium-a0a2f0c6fa125ca3594282f6fdb0e40d8adcbf8b.tar.gz
external_chromium-a0a2f0c6fa125ca3594282f6fdb0e40d8adcbf8b.tar.bz2
am 1c684ed1: Merge "Fix lazy-instance template to preserve object alignment on MIPS."
* commit '1c684ed1b5ac92ae473db5718627405367eb1766': Fix lazy-instance template to preserve object alignment on MIPS.
-rw-r--r--base/lazy_instance.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/base/lazy_instance.h b/base/lazy_instance.h
index 7b1bdc4..a8ff0e8 100644
--- a/base/lazy_instance.h
+++ b/base/lazy_instance.h
@@ -108,6 +108,14 @@ class BASE_API LazyInstanceHelper {
DISALLOW_COPY_AND_ASSIGN(LazyInstanceHelper);
};
+// Allow preservation of object alignment in the lazy instance when using GCC.
+// __alignof__ is only defined for GCC > 4.2.
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2))
+#define LAZY_ALIGN(T) __attribute__((aligned(__alignof__(T))))
+#else
+#define LAZY_ALIGN(T)
+#endif
+
template <typename Type, typename Traits = DefaultLazyInstanceTraits<Type> >
class LazyInstance : public LazyInstanceHelper {
public:
@@ -167,12 +175,15 @@ class LazyInstance : public LazyInstanceHelper {
base::subtle::Release_Store(&me->state_, STATE_EMPTY);
}
- int8 buf_[sizeof(Type)]; // Preallocate the space for the Type instance.
+ // Preallocate the space for the Type instance, and preserve alignment.
+ int8 buf_[sizeof(Type)] LAZY_ALIGN(Type);
Type *instance_;
DISALLOW_COPY_AND_ASSIGN(LazyInstance);
};
+#undef LAZY_ALIGN
+
} // namespace base
#endif // BASE_LAZY_INSTANCE_H_