Merge pull request #8354 from kjbracey-arm/singletonptr_align

SingletonPtr: const and alignment
pull/8375/merge
Cruz Monrreal 2018-10-17 08:35:12 -05:00 committed by GitHub
commit 7085d16661
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 6 deletions

View File

@ -88,7 +88,7 @@ struct SingletonPtr {
* @returns
* A pointer to the singleton
*/
T *get()
T *get() const
{
if (NULL == _ptr) {
singleton_lock();
@ -108,7 +108,7 @@ struct SingletonPtr {
* @returns
* A pointer to the singleton
*/
T *operator->()
T *operator->() const
{
return get();
}
@ -118,15 +118,20 @@ struct SingletonPtr {
* @returns
* A reference to the singleton
*/
T &operator*()
T &operator*() const
{
return *get();
}
// This is zero initialized when in global scope
T *_ptr;
// Force data to be 4 byte aligned
uint32_t _data[(sizeof(T) + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
mutable T *_ptr;
#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