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/2503/head
Russ Butler 2016-08-19 18:40:06 -05:00
parent 862db41be3
commit 707291ab68
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