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 47 PXR_NAMESPACE_OPEN_SCOPE
55 if (_instance.exchange(&instance) !=
nullptr) {
57 "GetInstance() or another SetInstanceConstructed() " 66 static std::atomic<bool> isInitializing;
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;
95 std::this_thread::yield();
99 return instance.load();
102 template <
typename T>
108 T *instance = _instance.load();
109 while (instance && !_instance.compare_exchange_weak(instance,
nullptr)) {
110 std::this_thread::yield();
122 #define TF_INSTANTIATE_SINGLETON(T) \ 123 template class PXR_NS_GLOBAL::TfSingleton<T> 126 PXR_NAMESPACE_CLOSE_SCOPE
Manage a single instance of an object.
Manage a single instance of an object (see.
Demangle C++ typenames generated by the typeid() facility.
static void SetInstanceConstructed(T &instance)
Indicate that the sole instance object has already been created.
#define TF_FATAL_ERROR(fmt, args)
Issue a fatal error and end the program.
static void DeleteInstance()
Destroy the sole instance object of type T, if it exists.
#define TF_AXIOM(cond)
Aborts if the condition cond is not met.
Stripped down version of diagnostic.h that doesn't define std::string.