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 using Handle = std::shared_ptr<T>;
24
25 Handle Get()
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
43protected:
44 virtual Handle _Compute() = 0;
45
46private:
47 Handle _data;
48};
49
50template<typename T>
51auto UsdSkelImagingGetTypedValue(
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
62PXR_NAMESPACE_CLOSE_SCOPE
63
64#endif
A thunk for shared pointers computing the result only once and using atomic operations to store the c...