mirror of https://github.com/ARMmbed/mbed-os.git
Fix SingletonPtr problems
Check to see if ptr is NULL after acquiring the singleton lock to prevent initialization race conditions. Also explicitly call the constructor for type T.pull/2590/head
parent
2564c4eafe
commit
fb3414fa43
|
@ -76,7 +76,9 @@ struct SingletonPtr {
|
||||||
T* get() {
|
T* get() {
|
||||||
if (NULL == _ptr) {
|
if (NULL == _ptr) {
|
||||||
singleton_lock();
|
singleton_lock();
|
||||||
_ptr = new (_data) T;
|
if (NULL == _ptr) {
|
||||||
|
_ptr = new (_data) T();
|
||||||
|
}
|
||||||
singleton_unlock();
|
singleton_unlock();
|
||||||
}
|
}
|
||||||
// _ptr was not zero initialized or was
|
// _ptr was not zero initialized or was
|
||||||
|
|
Loading…
Reference in New Issue