From 75d39d9ce5ebe2a091277f5dd1b4dcc95c7a1e11 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Wed, 26 Jan 2022 17:51:20 -0800 Subject: [PATCH] makes bucket variables atomic (#7179) Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- Code/Framework/AzCore/AzCore/Memory/HphaSchema.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/Memory/HphaSchema.cpp b/Code/Framework/AzCore/AzCore/Memory/HphaSchema.cpp index 6891eb4248..5e0e3e2de8 100644 --- a/Code/Framework/AzCore/AzCore/Memory/HphaSchema.cpp +++ b/Code/Framework/AzCore/AzCore/Memory/HphaSchema.cpp @@ -719,8 +719,12 @@ namespace AZ { #endif // DEBUG_ALLOCATOR - size_t mTotalAllocatedSizeBuckets = 0; - size_t mTotalCapacitySizeBuckets = 0; + // Bucket-dependent counters need to atomic since the locks that protect bucket allocations are per bucket + // So multiple threads could be updating these counters + AZStd::atomic mTotalAllocatedSizeBuckets = 0; + AZStd::atomic mTotalCapacitySizeBuckets = 0; + // In the case of tree allocations, there is a lock on the tree, so these counters are protected from multiple + // threads through that lock size_t mTotalAllocatedSizeTree = 0; size_t mTotalCapacitySizeTree = 0; public: