diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2024-09-25 11:56:44 -0400 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2024-09-25 11:56:44 -0400 |
commit | 55df7328c6f8c864ea309c57d73e791e079b3c2c (patch) | |
tree | cb4cba5e51d9649ba229c4eefeaafe783b9250e2 /indra/llcommon/llinttracker.h | |
parent | 4b2b94f4864f2e2e7d76f4f17b2d58bb959b3edb (diff) | |
parent | 86d2fb93b73d2689104c564ec859be7f83416691 (diff) |
Merge branch 'develop' into marchcat/xcode-16
Diffstat (limited to 'indra/llcommon/llinttracker.h')
-rw-r--r-- | indra/llcommon/llinttracker.h | 43 |
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) */ |