From c61b24441683c21893f0b96fdca2464d203ec912 Mon Sep 17 00:00:00 2001 From: amzn-mike <80125227+amzn-mike@users.noreply.github.com> Date: Fri, 23 Apr 2021 09:56:59 -0500 Subject: [PATCH] Use a const to toggle asset cancellation on and off --- .../AzCore/Asset/AssetInternal/WeakAsset.h | 33 +++++++++++++++---- .../Tests/Asset/AssetManagerLoadingTests.cpp | 2 +- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/Asset/AssetInternal/WeakAsset.h b/Code/Framework/AzCore/AzCore/Asset/AssetInternal/WeakAsset.h index 3d4fa6c50e..b772d5a8cb 100644 --- a/Code/Framework/AzCore/AzCore/Asset/AssetInternal/WeakAsset.h +++ b/Code/Framework/AzCore/AzCore/Asset/AssetInternal/WeakAsset.h @@ -28,6 +28,8 @@ namespace AZ::Data::AssetInternal class WeakAsset { public: + static constexpr bool EnableAssetCancellation = false; + WeakAsset() = default; WeakAsset(AssetData* assetData, AssetLoadBehavior assetReferenceLoadBehavior); @@ -111,7 +113,14 @@ namespace AZ::Data::AssetInternal // - If the left and right sides are the same, clearing the right side's reference means one less reference will exist if (m_assetData) { - m_assetData->ReleaseWeak(); + if constexpr (EnableAssetCancellation) + { + m_assetData->ReleaseWeak(); + } + else + { + m_assetData->Release(); + } } m_assetData = AZStd::move(rhs.m_assetData); rhs.m_assetData = nullptr; @@ -141,17 +150,27 @@ namespace AZ::Data::AssetInternal if (assetData) { - // This should be AcquireWeak but we're using strong references for now to disable asset cancellation - // until it is more stable - assetData->Acquire(); + if constexpr (EnableAssetCancellation) + { + assetData->AcquireWeak(); + } + else + { + assetData->Acquire(); + } m_assetId = assetData->GetId(); } if (m_assetData) { - // This should be ReleaseWeak but we're using strong references for now to disable asset cancellation - // until it is more stable - m_assetData->Release(); + if constexpr (EnableAssetCancellation) + { + m_assetData->ReleaseWeak(); + } + else + { + m_assetData->Release(); + } } m_assetData = assetData; diff --git a/Code/Framework/AzCore/Tests/Asset/AssetManagerLoadingTests.cpp b/Code/Framework/AzCore/Tests/Asset/AssetManagerLoadingTests.cpp index d2ffa34e5e..b9baf0db80 100644 --- a/Code/Framework/AzCore/Tests/Asset/AssetManagerLoadingTests.cpp +++ b/Code/Framework/AzCore/Tests/Asset/AssetManagerLoadingTests.cpp @@ -589,7 +589,7 @@ namespace UnitTest } }; - TEST_F(AssetJobsFloodTest, Cancel) + TEST_F(AssetJobsFloodTest, RapidAcquireAndRelease) { DebugListener listener; auto assetUuids = {