29 #ifdef PXR_BASE_TF_INSTANTIATE_SINGLETON_H
30 #error This file should only be included once in any given source (.cpp) file.
33 #define PXR_BASE_TF_INSTANTIATE_SINGLETON_H
42 #include "pxr/base/tf/mallocTag.h"
55 if (_instance.exchange(&instance) !=
nullptr) {
57 "GetInstance() or another SetInstanceConstructed() "
66 static std::atomic<bool> isInitializing;
68 TfAutoMallocTag2 tag(
"Tf",
"TfSingleton::_CreateInstance",
69 "Create Singleton " + ArchGetDemangled<T>());
74 if (isInitializing.exchange(
true) ==
false) {
81 T *curInst = instance.load();
83 if (curInst != newInst) {
88 TF_AXIOM(instance.exchange(newInst) ==
nullptr);
91 isInitializing =
false;
99 return instance.load();
102 template <
typename T>
108 T *instance = _instance.load();
109 while (instance && !_instance.compare_exchange_weak(instance,
nullptr)) {
122 #define TF_INSTANTIATE_SINGLETON(T) \
123 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()