summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2017-04-27 18:49:33 -0400
committerNat Goodspeed <nat@lindenlab.com>2017-04-27 18:49:33 -0400
commit29dd5f0123a89f44688477d04a421b90d1efe635 (patch)
tree8be4e3bfacb4005ddd61a96471c36b4434bb63e1 /indra/llcommon
parent2a5c47eb083a55cccb60916263b3c2b5d8d9c4fe (diff)
DRTVWR-418: Use (protected) LLSingleton to store "null instance"
of LLSafeHandle's referenced type. Using LLSingleton gives us a well-defined time at which the "null instance" is deleted: LLSingletonBase::deleteAll().
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/llsafehandle.h22
1 files changed, 16 insertions, 6 deletions
diff --git a/indra/llcommon/llsafehandle.h b/indra/llcommon/llsafehandle.h
index af1c26dd4f..74d31297a0 100644
--- a/indra/llcommon/llsafehandle.h
+++ b/indra/llcommon/llsafehandle.h
@@ -27,6 +27,7 @@
#define LLSAFEHANDLE_H
#include "llerror.h" // *TODO: consider eliminating this
+#include "llsingleton.h"
// Expands LLPointer to return a pointer to a special instance of class Type instead of NULL.
// This is useful in instances where operations on NULL pointers are semantically safe and/or
@@ -146,15 +147,24 @@ protected:
}
}
- static Type* nonNull(Type* ptr)
+ // Define an LLSingleton whose sole purpose is to hold a "null instance"
+ // of the subject Type: the canonical instance to dereference if this
+ // LLSafeHandle actually holds a null pointer. We use LLSingleton
+ // specifically so that the "null instance" can be cleaned up at a well-
+ // defined time, specifically LLSingletonBase::deleteAll().
+ // Of course, as with any LLSingleton, the "null instance" is only
+ // instantiated on demand -- in this case, if you actually try to
+ // dereference an LLSafeHandle containing null.
+ class NullInstanceHolder: public LLSingleton<NullInstanceHolder>
{
- return ptr == NULL ? sNullFunc() : ptr;
- }
+ LLSINGLETON_EMPTY_CTOR(NullInstanceHolder);
+ public:
+ Type mNullInstance;
+ };
- static Type* sNullFunc()
+ static Type* nonNull(Type* ptr)
{
- static Type sInstance;
- return &sInstance;
+ return ptr? ptr : &NullInstanceHolder::instance().mNullInstance;
}
protected: