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
31PXR_NAMESPACE_OPEN_SCOPE
35struct Tf_SingletonPyGILDropper
38 Tf_SingletonPyGILDropper();
40 ~Tf_SingletonPyGILDropper();
42#ifdef PXR_PYTHON_SUPPORT_ENABLED
43 std::unique_ptr<class TfPyLock> _pyLock;
53 if (_instance.exchange(&instance) !=
nullptr) {
55 "GetInstance() or another SetInstanceConstructed() "
64 static std::atomic<bool> isInitializing;
67 "Create Singleton " + ArchGetDemangled<T>());
71 Tf_SingletonPyGILDropper dropGIL;
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;
97 std::this_thread::yield();
101 return instance.load();
110 T *instance = _instance.load();
111 while (instance && !_instance.compare_exchange_weak(instance,
nullptr)) {
112 std::this_thread::yield();
124#define TF_INSTANTIATE_SINGLETON(T) \
125 template class PXR_NS_GLOBAL::TfSingleton<T>
128PXR_NAMESPACE_CLOSE_SCOPE
Manage a single instance of an object (see.
static void DeleteInstance()
Destroy the sole instance object of type T, if it exists.
static void SetInstanceConstructed(T &instance)
Indicate that the sole instance object has already been created.
Demangle C++ typenames generated by the typeid() facility.
Stripped down version of diagnostic.h that doesn't define std::string.
#define TF_AXIOM(cond)
Aborts if the condition cond is not met.
#define TF_FATAL_ERROR(fmt, args)
Issue a fatal error and end the program.
Manage a single instance of an object.