Refactor ThreadLocal when running on hardware with more cores than PLATFORM_THREADS_LIMIT

This commit is contained in:
Wojtek Figat
2024-02-07 23:39:02 +01:00
parent eed780a0b0
commit 082768d08c
20 changed files with 147 additions and 139 deletions

View File

@@ -211,7 +211,10 @@ FlaxStorage::~FlaxStorage()
#if USE_EDITOR
// Ensure to close any outstanding file handles to prevent file locking in case it failed to load
_file.DeleteAll();
Array<FileReadStream*> streams;
_file.GetValues(streams);
for (FileReadStream* stream : streams)
Delete(stream);
#endif
}
@@ -1264,7 +1267,6 @@ bool FlaxStorage::LoadAssetHeader(const Entry& e, AssetInitData& data)
}
#if ASSETS_LOADING_EXTRA_VERIFICATION
// Validate loaded header (asset ID and type ID must be the same)
if (e.ID != data.Header.ID)
{
@@ -1274,7 +1276,6 @@ bool FlaxStorage::LoadAssetHeader(const Entry& e, AssetInitData& data)
{
LOG(Error, "Loading asset header data mismatch! Expected Type Name: {0}, loaded header: {1}.\nSource: {2}", e.TypeName, data.Header.ToString(), ToString());
}
#endif
return false;
@@ -1337,7 +1338,11 @@ bool FlaxStorage::CloseFileHandles()
return true; // Failed, someone is still accessing the file
// Close file handles (from all threads)
_file.DeleteAll();
Array<FileReadStream*> streams;
_file.GetValues(streams);
for (FileReadStream* stream : streams)
Delete(stream);
_file.Clear();
return false;
}

View File

@@ -94,7 +94,7 @@ protected:
CriticalSection _loadLocker;
// Storage
ThreadLocalObject<FileReadStream> _file;
ThreadLocal<FileReadStream*> _file;
Array<FlaxChunk*> _chunks;
// Metadata