diff --git a/rocclr/runtime/device/pal/palresource.cpp b/rocclr/runtime/device/pal/palresource.cpp index f84ec1517d..73565bac0f 100644 --- a/rocclr/runtime/device/pal/palresource.cpp +++ b/rocclr/runtime/device/pal/palresource.cpp @@ -1837,7 +1837,6 @@ ResourceCache::~ResourceCache() { free(); } //! \note the cache works in FILO mode bool ResourceCache::addGpuMemory(Resource::Descriptor* desc, GpuMemoryReference* ref) { - amd::ScopedLock l(&lockCacheOps_); bool result = false; size_t size = ref->iMem()->Desc().size; @@ -1845,6 +1844,7 @@ bool ResourceCache::addGpuMemory(Resource::Descriptor* desc, GpuMemoryReference* if (((desc->type_ == Resource::Local) || (desc->type_ == Resource::Persistent) || (desc->type_ == Resource::Remote) || (desc->type_ == Resource::RemoteUSWC)) && (size < cacheSizeLimit_) && !desc->SVMRes_) { + amd::ScopedLock l(&lockCacheOps_); // Validate the cache size limit. Loop until we have enough space while ((cacheSize_ + size) > cacheSizeLimit_) { removeLast(); diff --git a/rocclr/runtime/device/pal/palresource.hpp b/rocclr/runtime/device/pal/palresource.hpp index e7f91440fd..b315fbcae4 100644 --- a/rocclr/runtime/device/pal/palresource.hpp +++ b/rocclr/runtime/device/pal/palresource.hpp @@ -478,8 +478,8 @@ class ResourceCache : public amd::HeapObject { amd::Monitor lockCacheOps_; //!< Lock to serialise cache access - size_t cacheSize_; //!< Current cache size in bytes - size_t cacheSizeLimit_; //!< Cache size limit in bytes + size_t cacheSize_; //!< Current cache size in bytes + const size_t cacheSizeLimit_; //!< Cache size limit in bytes //! CAL resource cache std::list > resCache_;