24 #ifndef PXR_USD_AR_THREAD_LOCAL_SCOPED_CACHE_H
25 #define PXR_USD_AR_THREAD_LOCAL_SCOPED_CACHE_H
33 #include <tbb/enumerable_thread_specific.h>
65 template <
class CachedType>
76 if (!cacheScopeData ||
83 _CachePtrStack& cacheStack = _threadCacheStack.local();
88 if (cacheStack.empty()) {
89 cacheStack.push_back(std::make_shared<CachedType>());
92 cacheStack.push_back(cacheStack.back());
95 *cacheScopeData = cacheStack.back();
100 _CachePtrStack& cacheStack = _threadCacheStack.local();
101 if (TF_VERIFY(!cacheStack.empty())) {
102 cacheStack.pop_back();
108 _CachePtrStack& cacheStack = _threadCacheStack.local();
109 return (cacheStack.empty() ?
CachePtr() : cacheStack.back());
113 using _CachePtrStack = std::vector<CachePtr>;
114 using _ThreadLocalCachePtrStack =
115 tbb::enumerable_thread_specific<_CachePtrStack>;
116 _ThreadLocalCachePtrStack _threadCacheStack;
121 #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)