mirror of https://github.com/ARMmbed/mbed-os.git
Align SingletonPtr data to 8 bytes, or use C++11
Be more cautious about alignment - align the data within a SingletonPtr to 8 bytes rather than 4. This could increase padding overhead by up to 8 bytes, sadly, but we may need this alignment for correct operation. Conditional check added for C++11 - if in use we can get correct minimal alignment by using alignas(T).pull/8354/head
parent
199d1667ff
commit
e7815c64ad
|
@ -125,8 +125,13 @@ struct SingletonPtr {
|
|||
|
||||
// This is zero initialized when in global scope
|
||||
mutable T *_ptr;
|
||||
// Force data to be 4 byte aligned
|
||||
mutable uint32_t _data[(sizeof(T) + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
|
||||
#if __cplusplus >= 201103L
|
||||
// Align data appropriately
|
||||
alignas(T) mutable char _data[sizeof(T)];
|
||||
#else
|
||||
// Force data to be 8 byte aligned
|
||||
mutable uint64_t _data[(sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t)];
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue