mirror of https://github.com/ARMmbed/mbed-os.git
Make SingletonPtr methods const
Make get() and operators * and -> of SingletonPtr const - they are logically const and thread-safe, despite the construction on first call. This construction is "invisible" to the caller of those methods.pull/8354/head
parent
fd4f47d18f
commit
199d1667ff
|
|
@ -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,15 @@ 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;
|
||||
mutable T *_ptr;
|
||||
// Force data to be 4 byte aligned
|
||||
uint32_t _data[(sizeof(T) + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
|
||||
mutable uint32_t _data[(sizeof(T) + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue