summaryrefslogtreecommitdiff
path: root/indra/llcommon/llinstancetracker.h
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-09-25 11:56:44 -0400
committerNat Goodspeed <nat@lindenlab.com>2024-09-25 11:56:44 -0400
commit55df7328c6f8c864ea309c57d73e791e079b3c2c (patch)
treecb4cba5e51d9649ba229c4eefeaafe783b9250e2 /indra/llcommon/llinstancetracker.h
parent4b2b94f4864f2e2e7d76f4f17b2d58bb959b3edb (diff)
parent86d2fb93b73d2689104c564ec859be7f83416691 (diff)
Merge branch 'develop' into marchcat/xcode-16
Diffstat (limited to 'indra/llcommon/llinstancetracker.h')
-rw-r--r--indra/llcommon/llinstancetracker.h88
1 files changed, 56 insertions, 32 deletions
diff --git a/indra/llcommon/llinstancetracker.h b/indra/llcommon/llinstancetracker.h
index 92b26354a1..b5c681e60a 100644
--- a/indra/llcommon/llinstancetracker.h
+++ b/indra/llcommon/llinstancetracker.h
@@ -41,6 +41,7 @@
#include <boost/iterator/indirect_iterator.hpp>
#include <boost/iterator/filter_iterator.hpp>
+#include "llprofiler.h"
#include "lockstatic.h"
#include "stringize.h"
@@ -80,6 +81,8 @@ class LLInstanceTracker
{
InstanceMap mMap;
};
+ // Unfortunately there's no umbrella class that owns all LLInstanceTracker
+ // instances, so there's no good place to call LockStatic::cleanup().
typedef llthread::LockStatic<StaticData> LockStatic;
public:
@@ -170,23 +173,7 @@ public:
}
// lock static data during construction
-#if ! LL_WINDOWS
LockStatic mLock;
-#else // LL_WINDOWS
- // We want to be able to use (e.g.) our instance_snapshot subclass as:
- // for (auto& inst : T::instance_snapshot()) ...
- // But when this snapshot base class directly contains LockStatic, as
- // above, Visual Studio 2017 requires us to code instead:
- // for (auto& inst : std::move(T::instance_snapshot())) ...
- // nat thinks this should be unnecessary, as an anonymous class
- // instance is already a temporary. It shouldn't need to be cast to
- // rvalue reference (the role of std::move()). clang evidently agrees,
- // as the short form works fine with Xcode on Mac.
- // To support the succinct usage, instead of directly storing
- // LockStatic, store std::shared_ptr<LockStatic>, which is copyable.
- std::shared_ptr<LockStatic> mLockp{std::make_shared<LockStatic>()};
- LockStatic& mLock{*mLockp};
-#endif // LL_WINDOWS
VectorType mData;
};
using snapshot = snapshot_of<T>;
@@ -276,6 +263,35 @@ protected:
public:
virtual const KEY& getKey() const { return mInstanceKey; }
+ /// for use ONLY for an object we're sure resides on the heap!
+ static bool erase(const KEY& key)
+ {
+ return erase(getInstance(key));
+ }
+
+ /// for use ONLY for an object we're sure resides on the heap!
+ static bool erase(const weak_t& ptr)
+ {
+ return erase(ptr.lock());
+ }
+
+ /// for use ONLY for an object we're sure resides on the heap!
+ static bool erase(const ptr_t& ptr)
+ {
+ if (! ptr)
+ {
+ return false;
+ }
+
+ // Because we store and return ptr_t instances with no-op deleters,
+ // merely resetting the last pointer doesn't destroy the referenced
+ // object. Don't even bother resetting 'ptr'. Just extract its raw
+ // pointer and delete that.
+ auto raw{ ptr.get() };
+ delete raw;
+ return true;
+ }
+
private:
LLInstanceTracker( const LLInstanceTracker& ) = delete;
LLInstanceTracker& operator=( const LLInstanceTracker& ) = delete;
@@ -356,6 +372,7 @@ class LLInstanceTracker<T, void, KEY_COLLISION_BEHAVIOR>
{
InstanceSet mSet;
};
+ // see LockStatic comment in the above specialization for non-void KEY
typedef llthread::LockStatic<StaticData> LockStatic;
public:
@@ -434,23 +451,7 @@ public:
}
// lock static data during construction
-#if ! LL_WINDOWS
LockStatic mLock;
-#else // LL_WINDOWS
- // We want to be able to use our instance_snapshot subclass as:
- // for (auto& inst : T::instance_snapshot()) ...
- // But when this snapshot base class directly contains LockStatic, as
- // above, Visual Studio 2017 requires us to code instead:
- // for (auto& inst : std::move(T::instance_snapshot())) ...
- // nat thinks this should be unnecessary, as an anonymous class
- // instance is already a temporary. It shouldn't need to be cast to
- // rvalue reference (the role of std::move()). clang evidently agrees,
- // as the short form works fine with Xcode on Mac.
- // To support the succinct usage, instead of directly storing
- // LockStatic, store std::shared_ptr<LockStatic>, which is copyable.
- std::shared_ptr<LockStatic> mLockp{std::make_shared<LockStatic>()};
- LockStatic& mLock{*mLockp};
-#endif // LL_WINDOWS
VectorType mData;
};
using snapshot = snapshot_of<T>;
@@ -481,6 +482,29 @@ public:
template <typename SUBCLASS>
using key_snapshot_of = instance_snapshot_of<SUBCLASS>;
+ /// for use ONLY for an object we're sure resides on the heap!
+ static bool erase(const weak_t& ptr)
+ {
+ return erase(ptr.lock());
+ }
+
+ /// for use ONLY for an object we're sure resides on the heap!
+ static bool erase(const ptr_t& ptr)
+ {
+ if (! ptr)
+ {
+ return false;
+ }
+
+ // Because we store and return ptr_t instances with no-op deleters,
+ // merely resetting the last pointer doesn't destroy the referenced
+ // object. Don't even bother resetting 'ptr'. Just extract its raw
+ // pointer and delete that.
+ auto raw{ ptr.get() };
+ delete raw;
+ return true;
+ }
+
protected:
LLInstanceTracker()
{