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