summaryrefslogtreecommitdiff
path: root/node/SharedPtr.hpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2016-09-02 12:34:02 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2016-09-02 12:34:02 -0700
commit4931e449989f74b9518d15bc69521fdbefb313e7 (patch)
treeae97532c0318b76bcc708f711a145c62bdd96323 /node/SharedPtr.hpp
parentd1101441b3d43ee69c1b661cc5f777a09fd10fca (diff)
downloadinfinitytier-4931e449989f74b9518d15bc69521fdbefb313e7.tar.gz
infinitytier-4931e449989f74b9518d15bc69521fdbefb313e7.zip
Implement "weak pointer" behavior on Topology Path canonicalization hash table.
Diffstat (limited to 'node/SharedPtr.hpp')
-rw-r--r--node/SharedPtr.hpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/node/SharedPtr.hpp b/node/SharedPtr.hpp
index 3ff5ed18..1dd3b43d 100644
--- a/node/SharedPtr.hpp
+++ b/node/SharedPtr.hpp
@@ -119,15 +119,39 @@ public:
inline T *ptr() const throw() { return _ptr; }
/**
- * Set this pointer to null
+ * Set this pointer to NULL
*/
inline void zero()
{
if (_ptr) {
if (--_ptr->__refCount <= 0)
delete _ptr;
+ _ptr = (T *)0;
+ }
+ }
+
+ /**
+ * Set this pointer to NULL if this is the only pointer holding the object
+ *
+ * @return True if object was deleted and SharedPtr is now NULL (or was already NULL)
+ */
+ inline bool reclaimIfWeak()
+ {
+ if (_ptr) {
+ if (++_ptr->__refCount <= 2) {
+ if (--_ptr->__refCount <= 1) {
+ delete _ptr;
+ _ptr = (T *)0;
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ } else {
+ return true;
}
- _ptr = (T *)0;
}
inline bool operator==(const SharedPtr &sp) const throw() { return (_ptr == sp._ptr); }