HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dataSourceUtils.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_IMAGING_USD_SKEL_IMAGING_DATA_SOURCE_UTILS_H
8 #define PXR_USD_IMAGING_USD_SKEL_IMAGING_DATA_SOURCE_UTILS_H
9 
11 
13 
14 /// \class UsdSkelImagingSharedPtrThunk
15 ///
16 /// A thunk for shared pointers computing the result only once and using
17 /// atomic operations to store the cached result.
18 ///
19 template<typename T>
21 {
22 public:
23  using Handle = std::shared_ptr<T>;
24 
26  {
27  if (auto const result = std::atomic_load(&_data)) {
28  return result;
29  }
30 
31  Handle expected;
32  Handle desired = _Compute();
33 
34  if (std::atomic_compare_exchange_strong(&_data, &expected, desired)) {
35  return desired;
36  } else {
37  return expected;
38  }
39  }
40 
41  void Invalidate() { std::atomic_store(&_data, Handle()); }
42 
43 protected:
44  virtual Handle _Compute() = 0;
45 
46 private:
47  Handle _data;
48 };
49 
50 template<typename T>
52  const T &ds,
53  const HdSampledDataSource::Time shutterOffset = 0.0f)
54  -> decltype(ds->GetTypedValue(0.0f))
55 {
56  if (!ds) {
57  return {};
58  }
59  return ds->GetTypedValue(shutterOffset);
60 }
61 
63 
64 #endif
std::shared_ptr< UsdSkelImagingSkelGuideData > Handle
auto UsdSkelImagingGetTypedValue(const T &ds, const HdSampledDataSource::Time shutterOffset=0.0f) -> decltype(ds->GetTypedValue(0.0f))
**But if you need a result
Definition: thread.h:622
GLfloat f
Definition: glcorearb.h:1926
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
virtual Handle _Compute()=0
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74