Skip to content

Commit 7579b91

Browse files
sunyabpixar-oss
authored andcommitted
usdShade: Use TfStaticData for shared UsdStageCache
Besides being recommended practice, this avoids a hang on Windows that could occur when the static UsdStageCache member was destroyed during process teardown. The UsdStage objects stored in the cache would try to use TBB in their d'tors after the TBB library had been unloaded and its worker threads destroyed, leading to odd deadlocks. This most recently showed up in testUsdChecker* but also affected imaging tests, which were disabled primarily because of this issue. (Internal change: 2353331)
1 parent 06a9c5e commit 7579b91

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

pxr/usd/usdShade/shaderDefParser.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include "pxr/usd/usd/stageCache.h"
1313

14+
#include "pxr/base/tf/staticData.h"
15+
1416
PXR_NAMESPACE_OPEN_SCOPE
1517

1618
TF_DEFINE_PRIVATE_TOKENS(
@@ -22,7 +24,7 @@ TF_DEFINE_PRIVATE_TOKENS(
2224
(usd)
2325
);
2426

25-
UsdStageCache UsdShadeShaderDefParserPlugin::_cache;
27+
static TfStaticData<UsdStageCache> _StageCache;
2628

2729
static
2830
NdrTokenMap
@@ -52,11 +54,10 @@ UsdShadeShaderDefParserPlugin::Parse(
5254
const std::string &rootLayerPath = discoveryResult.resolvedUri;
5355

5456
SdfLayerRefPtr rootLayer = SdfLayer::FindOrOpen(rootLayerPath);
55-
UsdStageRefPtr stage =
56-
UsdShadeShaderDefParserPlugin::_cache.FindOneMatching(rootLayer);
57+
UsdStageRefPtr stage = _StageCache->FindOneMatching(rootLayer);
5758
if (!stage) {
5859
stage = UsdStage::Open(rootLayer);
59-
UsdShadeShaderDefParserPlugin::_cache.Insert(stage);
60+
_StageCache->Insert(stage);
6061
}
6162

6263
if (!stage) {

pxr/usd/usdShade/shaderDefParser.h

-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
PXR_NAMESPACE_OPEN_SCOPE
1717

18-
class UsdStageCache;
19-
2018
/// \class UsdShadeShaderDefParserPlugin
2119
///
2220
/// Parses shader definitions represented using USD scene description using the
@@ -40,9 +38,6 @@ class UsdShadeShaderDefParserPlugin : public NdrParserPlugin
4038

4139
USDSHADE_API
4240
const TfToken &GetSourceType() const override;
43-
44-
private:
45-
static UsdStageCache _cache;
4641
};
4742

4843
PXR_NAMESPACE_CLOSE_SCOPE

0 commit comments

Comments
 (0)