Fix crash in animations system when assets gets loading/unloaded while async jobs are active

#2974
This commit is contained in:
Wojtek Figat
2025-02-18 22:30:49 +01:00
parent c81ddd09cc
commit 060bc0aaf8
7 changed files with 118 additions and 3 deletions

View File

@@ -0,0 +1,46 @@
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Core/Core.h"
#include "Engine/Core/Types/BaseTypes.h"
/// <summary>
/// Utility for guarding system data access from different threads depending on the resources usage (eg. block read on write).
/// </summary>
struct ConcurrentSystemLocker
{
private:
volatile int64 _counters[2];
public:
NON_COPYABLE(ConcurrentSystemLocker);
ConcurrentSystemLocker();
void Begin(bool write);
void End(bool write);
public:
template<bool Write>
struct Scope
{
NON_COPYABLE(Scope);
Scope(ConcurrentSystemLocker& locker)
: _locker(locker)
{
_locker.Begin(Write);
}
~Scope()
{
_locker.End(Write);
}
private:
ConcurrentSystemLocker& _locker;
};
typedef Scope<false> ReadScope;
typedef Scope<true> WriteScope;
};