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
Russ Butler 2016-08-19 18:40:06 -05:00 committed by 0xc0170
parent 2564c4eafe
commit fb3414fa43
1 changed files with 3 additions and 1 deletions

View File

@ -76,7 +76,9 @@ struct SingletonPtr {
T* get() {
if (NULL == _ptr) {
singleton_lock();
_ptr = new (_data) T;
if (NULL == _ptr) {
_ptr = new (_data) T();
}
singleton_unlock();
}
// _ptr was not zero initialized or was