7 #ifndef PXR_BASE_TF_STACKED_H
8 #define PXR_BASE_TF_STACKED_H
15 #include <tbb/enumerable_thread_specific.h>
18 #include <type_traits>
31 template <
class Derived>
33 return Derived::_InitializeStack();
38 template <
typename T,
bool PerThread>
41 typedef std::vector<T const *>
Stack;
48 _StackHolder() : _initialized(
false) { }
53 TfStackedAccess::InitializeStack<T>();
63 struct _PerThreadStackStorage {
64 tbb::enumerable_thread_specific<_StackHolder> stack;
66 return stack.local().Get();
70 struct _GlobalStackStorage {
79 typedef typename std::conditional<
80 PerThread, _PerThreadStackStorage, _GlobalStackStorage
86 template <
typename T,
bool PerThread>
92 template <
typename T,
bool PerThread>
96 static std::atomic<Type*>
value;
118 template <
class Derived,
bool PerThread =
true,
126 typedef typename Storage::Stack
Stack;
144 return stack.empty() ? 0 : stack.back();
154 size_t size = stack.size();
155 return size <= 1 ? 0 : stack[size-2];
175 static void _InitializeStack() {}
178 static void _Push(Derived
const *p) {
179 _GetStack().push_back(p);
183 static void _Pop(Derived
const *p) {
186 _GetStack().pop_back();
190 ArchGetDemangled<Derived>().
c_str());
195 static Stack &_GetStack() {
199 _StorageType *old =
nullptr;
200 _StorageType *tmp =
new _StorageType;
210 Derived *_AsDerived() {
211 return static_cast<Derived *
>(
this);
214 Derived
const *_AsDerived()
const {
215 return static_cast<Derived
const *
>(
this);
223 #define TF_DEFINE_STACKED(Derived, IsPerThread, eiAPI) \
226 struct Tf_ExportedStackedStorage<Derived, IsPerThread> { \
227 typedef typename Tf_StackedStorageType<Derived, IsPerThread>::Stack Stack; \
228 typedef typename Tf_StackedStorageType<Derived, IsPerThread>::Type Type; \
229 static eiAPI std::atomic<Type*> value; \
232 public TfStacked<Derived, IsPerThread, \
233 Tf_ExportedStackedStorage<Derived, IsPerThread>>
237 #endif // PXR_BASE_TF_STACKED_H
static bool IsStackTop(Derived const *p)
Returns true if p is the top of the stack.
~TfStacked()
Pops this stacked object from the stack.
TfStacked()
Pushes this stacked object onto the stack.
static void InitializeStack()
GLsizei const GLfloat * value
Tf_StackedStorageType< T, PerThread >::Type Type
static Derived const * GetStackTop()
static Stack const & GetStack()
Returns a const reference to the entire stack.
GLint GLint GLsizei GLint GLenum GLenum type
static Derived const * GetStackPrevious()
std::conditional< PerThread, _PerThreadStackStorage, _GlobalStackStorage >::type Type
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
static std::atomic< Type * > value
#define PXR_NAMESPACE_CLOSE_SCOPE
OIIO_UTIL_API const char * c_str(string_view str)
std::vector< T const * > Stack
Tf_StackedStorageType< T, PerThread >::Stack Stack