Fix FlaxStorage refs counting to be atomic

This commit is contained in:
Wojciech Figat
2022-08-16 12:36:44 +02:00
parent 31fb4f6a15
commit 0b15c369d6
2 changed files with 21 additions and 26 deletions

View File

@@ -201,23 +201,6 @@ FlaxStorage::FlaxStorage(const StringView& path)
{
}
void FlaxStorage::AddRef()
{
_refCount++;
}
void FlaxStorage::RemoveRef()
{
if (_refCount > 0)
{
_refCount--;
if (_refCount == 0)
{
_lastRefLostTime = DateTime::NowUTC();
}
}
}
FlaxStorage::~FlaxStorage()
{
// Validate if has been disposed
@@ -237,9 +220,14 @@ FlaxStorage::LockData FlaxStorage::LockSafe()
return lock;
}
uint32 FlaxStorage::GetRefCount() const
{
return (uint32)Platform::AtomicRead((int64*)&_refCount);
}
bool FlaxStorage::ShouldDispose() const
{
return _refCount == 0 && Platform::AtomicRead((int64*)&_chunksLock) == 0 && DateTime::NowUTC() - _lastRefLostTime >= TimeSpan::FromMilliseconds(500);
return Platform::AtomicRead((int64*)&_refCount) == 0 && Platform::AtomicRead((int64*)&_chunksLock) == 0 && DateTime::NowUTC() - _lastRefLostTime >= TimeSpan::FromMilliseconds(500);
}
uint32 FlaxStorage::GetMemoryUsage() const