Skip to content

Commit

Permalink
am 1c684ed: Merge "Fix lazy-instance template to preserve object alig…
Browse files Browse the repository at this point in the history
…nment on MIPS."

* commit '1c684ed1b5ac92ae473db5718627405367eb1766':
  Fix lazy-instance template to preserve object alignment on MIPS.
  • Loading branch information
Jean-Baptiste Queru authored and Android Git Automerger committed Aug 10, 2012
2 parents e20b4bd + 1c684ed commit a0a2f0c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion base/lazy_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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_

0 comments on commit a0a2f0c

Please sign in to comment.