24 #ifndef PXR_USD_AR_THREAD_LOCAL_SCOPED_CACHE_H 25 #define PXR_USD_AR_THREAD_LOCAL_SCOPED_CACHE_H 28 #include "pxr/usd/ar/api.h" 30 #include "pxr/base/vt/value.h" 33 #include <tbb/enumerable_thread_specific.h> 37 PXR_NAMESPACE_OPEN_SCOPE
65 template <
class CachedType>
69 using CachePtr = std::shared_ptr<CachedType>;
71 void BeginCacheScope(
VtValue* cacheScopeData)
76 if (!cacheScopeData ||
78 !cacheScopeData->
IsHolding<CachePtr>())) {
83 _CachePtrStack& cacheStack = _threadCacheStack.local();
84 if (cacheScopeData->
IsHolding<CachePtr>()) {
85 cacheStack.push_back(cacheScopeData->
UncheckedGet<CachePtr>());
88 if (cacheStack.empty()) {
89 cacheStack.push_back(std::make_shared<CachedType>());
92 cacheStack.push_back(cacheStack.back());
95 *cacheScopeData = cacheStack.back();
98 void EndCacheScope(
VtValue* cacheScopeData)
100 _CachePtrStack& cacheStack = _threadCacheStack.local();
102 cacheStack.pop_back();
106 CachePtr GetCurrentCache()
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;
119 PXR_NAMESPACE_CLOSE_SCOPE
121 #endif // PXR_USD_AR_THREAD_LOCAL_SCOPED_CACHE_H T const & UncheckedGet() const &
Returns a const reference to the held object if the held object is of type T.
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
Low-level utilities for informing users of various internal and external diagnostic conditions.
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
bool IsEmpty() const
Returns true iff this value is empty.
Utility class for custom resolver implementations.
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
Provides a container which may hold any type, and provides introspection and iteration over array typ...