Skip to content

Commit 707291a

Browse files
committed
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.
1 parent 862db41 commit 707291a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

hal/api/SingletonPtr.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ struct SingletonPtr {
7676
T* get() {
7777
if (NULL == _ptr) {
7878
singleton_lock();
79-
_ptr = new (_data) T;
79+
if (NULL == _ptr) {
80+
_ptr = new (_data) T();
81+
}
8082
singleton_unlock();
8183
}
8284
// _ptr was not zero initialized or was

0 commit comments

Comments
 (0)