diff --git a/Source/Engine/Content/Asset.cpp b/Source/Engine/Content/Asset.cpp index 5a9e62993..559a673da 100644 --- a/Source/Engine/Content/Asset.cpp +++ b/Source/Engine/Content/Asset.cpp @@ -242,9 +242,8 @@ void Asset::AddReference(IAssetReference* ref, bool week) if (ref) { //PROFILE_MEM(EngineDelegate); // Include references tracking memory within Delegate memory - Locker.Lock(); + ScopeLock lock(_referencesLocker); _references.Add(ref); - Locker.Unlock(); } } @@ -257,9 +256,8 @@ void Asset::RemoveReference(IAssetReference* ref, bool week) { if (ref) { - Locker.Lock(); + ScopeLock lock(_referencesLocker); _references.Remove(ref); - Locker.Unlock(); } if (!week) Platform::InterlockedDecrement(&_refCount); @@ -681,6 +679,7 @@ void Asset::onLoaded_MainThread() ASSERT(IsInMainThread()); // Send event + ScopeLock lock(_referencesLocker); for (const auto& e : _references) e.Item->OnAssetLoaded(this, this); OnLoaded(this); @@ -696,6 +695,7 @@ void Asset::onUnload_MainThread() CancelStreaming(); // Send event + ScopeLock lock(_referencesLocker); for (const auto& e : _references) e.Item->OnAssetUnloaded(this, this); OnUnloaded(this); diff --git a/Source/Engine/Content/Asset.h b/Source/Engine/Content/Asset.h index bb0fbe490..c838eddf8 100644 --- a/Source/Engine/Content/Asset.h +++ b/Source/Engine/Content/Asset.h @@ -7,6 +7,7 @@ #include "Engine/Core/Types/String.h" #include "Engine/Platform/CriticalSection.h" #include "Engine/Scripting/ScriptingObject.h" +#include "Engine/Threading/ConcurrentSystemLocker.h" #include "Config.h" #include "Types.h" @@ -63,6 +64,7 @@ protected: int8 _isVirtual : 1; // Indicates that asset is pure virtual (generated or temporary, has no storage so won't be saved) HashSet _references; + CriticalSection _referencesLocker; // TODO: convert into a single interlocked exchange for the current thread owning lock public: ///