mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-21 22:07:49 +00:00
Merge branch 'dev' into edge
This commit is contained in:
commit
9da7967197
@ -76,8 +76,9 @@ public:
|
|||||||
*
|
*
|
||||||
* @param ptr Naked pointer to assign
|
* @param ptr Naked pointer to assign
|
||||||
*/
|
*/
|
||||||
inline void setToUnsafe(T *ptr)
|
inline void set(T *ptr)
|
||||||
{
|
{
|
||||||
|
zero();
|
||||||
++ptr->__refCount;
|
++ptr->__refCount;
|
||||||
_ptr = ptr;
|
_ptr = ptr;
|
||||||
}
|
}
|
||||||
@ -116,27 +117,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set this pointer to NULL if this is the only pointer holding the object
|
* @return Number of references according to this object's ref count or 0 if NULL
|
||||||
*
|
|
||||||
* @return True if object was deleted and SharedPtr is now NULL (or was already NULL)
|
|
||||||
*/
|
*/
|
||||||
inline bool reclaimIfWeak()
|
inline int references()
|
||||||
{
|
{
|
||||||
if (_ptr) {
|
if (_ptr)
|
||||||
if (++_ptr->__refCount <= 2) {
|
return _ptr->__refCount.load();
|
||||||
if (--_ptr->__refCount <= 1) {
|
return 0;
|
||||||
delete _ptr;
|
|
||||||
_ptr = (T *)0;
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator==(const SharedPtr &sp) const { return (_ptr == sp._ptr); }
|
inline bool operator==(const SharedPtr &sp) const { return (_ptr == sp._ptr); }
|
||||||
|
@ -388,7 +388,7 @@ void Topology::doPeriodicTasks(void *tPtr,int64_t now)
|
|||||||
Path::HashKey *k = (Path::HashKey *)0;
|
Path::HashKey *k = (Path::HashKey *)0;
|
||||||
SharedPtr<Path> *p = (SharedPtr<Path> *)0;
|
SharedPtr<Path> *p = (SharedPtr<Path> *)0;
|
||||||
while (i.next(k,p)) {
|
while (i.next(k,p)) {
|
||||||
if (p->reclaimIfWeak())
|
if (p->references() <= 1)
|
||||||
_paths.erase(*k);
|
_paths.erase(*k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ public:
|
|||||||
Mutex::Lock _l(_paths_m);
|
Mutex::Lock _l(_paths_m);
|
||||||
SharedPtr<Path> &p = _paths[Path::HashKey(l,r)];
|
SharedPtr<Path> &p = _paths[Path::HashKey(l,r)];
|
||||||
if (!p)
|
if (!p)
|
||||||
p.setToUnsafe(new Path(l,r));
|
p.set(new Path(l,r));
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user