Another attempt on 6a883bc7c6

This commit is contained in:
Wojtek Figat
2024-05-15 11:22:07 +02:00
parent 6a883bc7c6
commit 6f2bd0e932
2 changed files with 16 additions and 8 deletions

View File

@@ -218,10 +218,7 @@ const Char* TypeId2TypeName(const uint32 typeId)
}
FlaxStorage::FlaxStorage(const StringView& path)
: _refCount(0)
, _chunksLock(0)
, _version(0)
, _path(path)
: _path(path)
{
}
@@ -242,6 +239,7 @@ FlaxStorage::~FlaxStorage()
if (stream)
Delete(stream);
}
Platform::AtomicStore(&_files, 0);
#endif
}
@@ -1327,6 +1325,7 @@ FileReadStream* FlaxStorage::OpenFile()
LOG(Error, "Cannot open Flax Storage file \'{0}\'.", _path);
return nullptr;
}
Platform::InterlockedIncrement(&_files);
// Create file reading stream
stream = New<FileReadStream>(file);
@@ -1336,6 +1335,13 @@ FileReadStream* FlaxStorage::OpenFile()
bool FlaxStorage::CloseFileHandles()
{
if (Platform::AtomicRead(&_chunksLock) == 0 && Platform::AtomicRead(&_files) == 0)
{
Array<FileReadStream*, InlinedAllocation<8>> streams;
_file.GetValues(streams);
ASSERT(streams.Count() == 0);
return false;
}
PROFILE_CPU();
// Note: this is usually called by the content manager when this file is not used or on exit
@@ -1367,7 +1373,7 @@ bool FlaxStorage::CloseFileHandles()
return true; // Failed, someone is still accessing the file
// Close file handles (from all threads)
Array<FileReadStream*> streams;
Array<FileReadStream*, InlinedAllocation<8>> streams;
_file.GetValues(streams);
for (FileReadStream* stream : streams)
{
@@ -1375,6 +1381,7 @@ bool FlaxStorage::CloseFileHandles()
Delete(stream);
}
_file.Clear();
Platform::AtomicStore(&_files, 0);
return false;
}

View File

@@ -87,8 +87,9 @@ public:
protected:
// State
int64 _refCount;
int64 _chunksLock;
int64 _refCount = 0;
int64 _chunksLock = 0;
int64 _files = 0;
double _lastRefLostTime;
CriticalSection _loadLocker;
@@ -97,7 +98,7 @@ protected:
Array<FlaxChunk*> _chunks;
// Metadata
uint32 _version;
uint32 _version = 0;
String _path;
protected: