summaryrefslogtreecommitdiff
path: root/indra/llcommon/llinttracker.h
diff options
context:
space:
mode:
authornat-goodspeed <nat@lindenlab.com>2024-09-05 14:30:27 -0400
committerGitHub <noreply@github.com>2024-09-05 14:30:27 -0400
commit18d81e20f0b0044c16615953d7b69d7fb34d3449 (patch)
tree2b3f02ad060c0f4a55f2ff8b3ec53dc3f3b8f60b /indra/llcommon/llinttracker.h
parent7ac4c3b56e5246fceaa73e7c9c665d3c04827d6c (diff)
parent49bf86b52459b183d3988388dbb74d8888a71925 (diff)
Merge pull request #2451 from secondlife/lua-resultset
Give certain `LLInventoryListener` queries an API based on result sets.
Diffstat (limited to 'indra/llcommon/llinttracker.h')
-rw-r--r--indra/llcommon/llinttracker.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/indra/llcommon/llinttracker.h b/indra/llcommon/llinttracker.h
new file mode 100644
index 0000000000..fd6d24d0fd
--- /dev/null
+++ b/indra/llcommon/llinttracker.h
@@ -0,0 +1,43 @@
+/**
+ * @file llinttracker.h
+ * @author Nat Goodspeed
+ * @date 2024-08-30
+ * @brief LLIntTracker isa LLInstanceTracker with generated int keys.
+ *
+ * $LicenseInfo:firstyear=2024&license=viewerlgpl$
+ * Copyright (c) 2024, Linden Research, Inc.
+ * $/LicenseInfo$
+ */
+
+#if ! defined(LL_LLINTTRACKER_H)
+#define LL_LLINTTRACKER_H
+
+#include "llinstancetracker.h"
+
+template <typename T>
+class LLIntTracker: public LLInstanceTracker<T, int>
+{
+ using super = LLInstanceTracker<T, int>;
+public:
+ LLIntTracker():
+ super(getUniqueKey())
+ {}
+
+private:
+ static int getUniqueKey()
+ {
+ // Find a random key that does NOT already correspond to an instance.
+ // Passing a duplicate key to LLInstanceTracker would do Bad Things.
+ int key;
+ do
+ {
+ key = std::rand();
+ } while (super::getInstance(key));
+ // This could be racy, if we were instantiating new LLIntTracker<T>s
+ // on multiple threads. If we need that, have to lock between checking
+ // getInstance() and constructing the new super.
+ return key;
+ }
+};
+
+#endif /* ! defined(LL_LLINTTRACKER_H) */