diff options
author | Paul Lind <plind@mips.com> | 2012-08-07 22:27:52 -0700 |
---|---|---|
committer | Paul Lind <plind@mips.com> | 2012-08-07 22:27:52 -0700 |
commit | 5dd41b50fc7d24c103522171ec2b3b89b7c0d37f (patch) | |
tree | 87925b2b746c804e1615bf7de1b0c8c7f83e8a11 /base | |
parent | 0abec4daa38319f371ac6555e7887f6b14f34291 (diff) | |
download | external_chromium-5dd41b50fc7d24c103522171ec2b3b89b7c0d37f.zip external_chromium-5dd41b50fc7d24c103522171ec2b3b89b7c0d37f.tar.gz external_chromium-5dd41b50fc7d24c103522171ec2b3b89b7c0d37f.tar.bz2 |
Fix lazy-instance template to preserve object alignment on MIPS.
The alignment attribute of an object was discarded when allocating storage
for the lazy-instance. Alignment is important for MIPS, where doubles
(and objects containing them) must be aligned on 8-byte boundary.
The alignment attributes are included via a macro that is only defined
under GCC, so that this change does not affect other build enviromments.
Change-Id: I99047cf610618de2e7e29e5de85835dc45d99231
Signed-off-by: Paul Lind <plind@mips.com>
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_ |