Loading...
Searching...
No Matches
dataSourceUtils.h
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
10#include "pxr/imaging/hd/dataSource.h"
11
12PXR_NAMESPACE_OPEN_SCOPE
13
19template<typename T>
21{
22public:
23 virtual ~UsdSkelImagingSharedPtrThunk() = default;
24
25 using Handle = std::shared_ptr<T>;
26
27 Handle Get()
28 {
29 if (auto const result = std::atomic_load(&_data)) {
30 return result;
31 }
32
33 Handle expected;
34 Handle desired = _Compute();
35
36 if (std::atomic_compare_exchange_strong(&_data, &expected, desired)) {
37 return desired;
38 } else {
39 return expected;
40 }
41 }
42
43 void Invalidate() { std::atomic_store(&_data, Handle()); }
44
45protected:
46 virtual Handle _Compute() = 0;
47
48private:
49 Handle _data;
50};
51
52template<typename T>
53auto UsdSkelImagingGetTypedValue(
54 const T &ds,
55 const HdSampledDataSource::Time shutterOffset = 0.0f)
56 -> decltype(ds->GetTypedValue(0.0f))
57{
58 if (!ds) {
59 return {};
60 }
61 return ds->GetTypedValue(shutterOffset);
62}
63
64PXR_NAMESPACE_CLOSE_SCOPE
65
66#endif
A thunk for shared pointers computing the result only once and using atomic operations to store the c...