12 #ifdef PXR_BASE_TF_INSTANTIATE_SINGLETON_H
13 #error This file should only be included once in any given source (.cpp) file.
16 #define PXR_BASE_TF_INSTANTIATE_SINGLETON_H
25 #include "pxr/base/tf/mallocTag.h"
42 #ifdef PXR_PYTHON_SUPPORT_ENABLED
43 std::unique_ptr<class TfPyLock> _pyLock;
44 #endif // PXR_PYTHON_SUPPORT_ENABLED
53 if (_instance.exchange(&instance) !=
nullptr) {
55 "GetInstance() or another SetInstanceConstructed() "
64 static std::atomic<bool> isInitializing;
66 TfAutoMallocTag2 tag(
"Tf",
"TfSingleton::_CreateInstance",
67 "Create Singleton " + ArchGetDemangled<T>());
76 if (isInitializing.exchange(
true) ==
false) {
83 T *curInst = instance.load();
85 if (curInst != newInst) {
90 TF_AXIOM(instance.exchange(newInst) ==
nullptr);
93 isInitializing =
false;
101 return instance.load();
104 template <
typename T>
110 T *instance = _instance.load();
111 while (instance && !_instance.compare_exchange_weak(instance,
nullptr)) {
124 #define TF_INSTANTIATE_SINGLETON(T) \
125 template class PXR_NS_GLOBAL::TfSingleton<T>
static void SetInstanceConstructed(T &instance)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
#define PXR_NAMESPACE_CLOSE_SCOPE
static void DeleteInstance()
TF_API Tf_SingletonPyGILDropper()
TF_API ~Tf_SingletonPyGILDropper()