7 #ifndef PXR_USD_AR_THREAD_LOCAL_SCOPED_CACHE_H
8 #define PXR_USD_AR_THREAD_LOCAL_SCOPED_CACHE_H
16 #include <tbb/enumerable_thread_specific.h>
48 template <
class CachedType>
59 if (!cacheScopeData ||
66 _CachePtrStack& cacheStack = _threadCacheStack.local();
71 if (cacheStack.empty()) {
72 cacheStack.push_back(std::make_shared<CachedType>());
75 cacheStack.push_back(cacheStack.back());
78 *cacheScopeData = cacheStack.back();
83 _CachePtrStack& cacheStack = _threadCacheStack.local();
84 if (TF_VERIFY(!cacheStack.empty())) {
85 cacheStack.pop_back();
91 _CachePtrStack& cacheStack = _threadCacheStack.local();
92 return (cacheStack.empty() ?
CachePtr() : cacheStack.back());
96 using _CachePtrStack = std::vector<CachePtr>;
97 using _ThreadLocalCachePtrStack =
98 tbb::enumerable_thread_specific<_CachePtrStack>;
99 _ThreadLocalCachePtrStack _threadCacheStack;
104 #endif // PXR_USD_AR_THREAD_LOCAL_SCOPED_CACHE_H
T const & UncheckedGet() const &
bool IsEmpty() const
Returns true iff this value is empty.
CachePtr GetCurrentCache()
void BeginCacheScope(VtValue *cacheScopeData)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
#define PXR_NAMESPACE_CLOSE_SCOPE
std::shared_ptr< CachedType > CachePtr
void EndCacheScope(VtValue *cacheScopeData)