diff options
author | Jean-Baptiste Queru <jbq@google.com> | 2012-08-10 09:42:09 -0700 |
---|---|---|
committer | android code review <noreply-gerritcodereview@google.com> | 2012-08-10 09:42:09 -0700 |
commit | 1c684ed1b5ac92ae473db5718627405367eb1766 (patch) | |
tree | c7ad0ca557206bd855dd15f79b79f86a5f33fde6 /base | |
parent | 2af13d061b168f46912c78a76f20bc3956422ca5 (diff) | |
parent | 5dd41b50fc7d24c103522171ec2b3b89b7c0d37f (diff) | |
download | external_chromium-1c684ed1b5ac92ae473db5718627405367eb1766.zip external_chromium-1c684ed1b5ac92ae473db5718627405367eb1766.tar.gz external_chromium-1c684ed1b5ac92ae473db5718627405367eb1766.tar.bz2 |
Merge "Fix lazy-instance template to preserve object alignment on MIPS."
Diffstat (limited to 'base')
-rw-r--r-- | base/lazy_instance.h | 13 |
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_ |