mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #8354 from kjbracey-arm/singletonptr_align
SingletonPtr: const and alignmentpull/8375/merge
commit
7085d16661
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue