24 #ifndef PXR_USD_SDF_POOL_H
25 #define PXR_USD_SDF_POOL_H
36 #include <tbb/concurrent_queue.h>
50 static thread_local
T *theTPtr =
nullptr;
54 static thread_local
T theT;
78 unsigned ElemsPerSpan=16384>
81 static_assert(ElemSize >=
sizeof(uint32_t),
82 "ElemSize must be at least sizeof(uint32_t)");
92 static constexpr uint32_t
RegionMask = ((1 << RegionBits)-1);
98 constexpr
Handle() noexcept =
default;
101 :
value((index << RegionBits) | region) {}
111 return Sdf_Pool::_GetHandle(
ptr);
113 explicit operator bool()
const {
135 char *p =
head.GetPtr();
142 char *p = h.GetPtr();
156 size_t size()
const {
return endIndex - beginIndex; }
158 return Handle(region, beginIndex++);
160 inline bool empty()
const {
161 return beginIndex == endIndex;
168 struct _PerThreadData {
179 struct _RegionState {
180 static constexpr uint32_t LockedState = ~0;
182 _RegionState() =
default;
183 constexpr _RegionState(
unsigned region, uint32_t
index)
184 : _state((index << RegionBits) | region) {}
188 inline _RegionState Reserve(
unsigned num)
const;
190 static constexpr _RegionState GetInitState() {
191 return _RegionState(0, 0);
194 static constexpr _RegionState GetLockedState() {
195 return _RegionState(LockedState, LockedState);
198 constexpr
bool operator==(_RegionState other)
const {
199 return _state == other._state;
203 return _state >> RegionBits;
206 unsigned GetRegion()
const {
210 bool IsLocked()
const {
211 return _state == LockedState;
225 static inline char *_GetPtr(
unsigned region, uint32_t
index) {
231 return _regionStarts[region] + (index * ElemSize);
237 static inline Handle _GetHandle(
char const *
ptr) {
239 for (
unsigned region = 1; region != NumRegions+1; ++region) {
253 region, static_cast<uint32_t>(diff / ElemSize));
261 static bool _TakeSharedFreeList(_FreeList &out) {
262 return _sharedFreeLists->try_pop(out);
266 static void _ShareFreeList(_FreeList &in) {
267 _sharedFreeLists->push(in);
272 static inline void _ReserveSpan(_PoolSpan &out);
274 static constexpr
int NumRegions = 1 << RegionBits;
277 SDF_API static _ThreadData _threadData;
278 SDF_API static char *_regionStarts[NumRegions+1];
279 SDF_API static std::atomic<_RegionState> _regionState;
285 #endif // PXR_USD_SDF_POOL_H
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
UT_StringArray JOINTS head
constexpr Handle(std::nullptr_t) noexcept
fallback_uintptr uintptr_t
static constexpr uint32_t RegionMask
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
bool operator!=(Handle const &r) const noexcept
#define ARCH_PRAGMA_UNDEFINED_VAR_TEMPLATE
GLfloat GLfloat GLfloat GLfloat h
void swap(Handle &r) noexcept
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
#define ARCH_PRAGMA_MAYBE_UNINITIALIZED
char * GetPtr() const noexcept
bool operator==(Handle const &r) const noexcept
#define PXR_NAMESPACE_CLOSE_SCOPE
static Handle GetHandle(char const *ptr) noexcept
bool operator<(Handle const &r) const noexcept
constexpr Handle() noexcept=default
Handle & operator=(std::nullptr_t)
Handle & operator=(Handle const &)=default
static constexpr uint64_t ElemsPerRegion
static void Free(Handle h)
constexpr FMT_INLINE value()
GLenum GLenum GLsizei void GLsizei void void * span
static constexpr uint32_t MaxIndex
Handle(unsigned region, uint32_t index)