Another attempt on 6a883bc7c6
This commit is contained in:
@@ -218,10 +218,7 @@ const Char* TypeId2TypeName(const uint32 typeId)
|
|||||||
}
|
}
|
||||||
|
|
||||||
FlaxStorage::FlaxStorage(const StringView& path)
|
FlaxStorage::FlaxStorage(const StringView& path)
|
||||||
: _refCount(0)
|
: _path(path)
|
||||||
, _chunksLock(0)
|
|
||||||
, _version(0)
|
|
||||||
, _path(path)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,6 +239,7 @@ FlaxStorage::~FlaxStorage()
|
|||||||
if (stream)
|
if (stream)
|
||||||
Delete(stream);
|
Delete(stream);
|
||||||
}
|
}
|
||||||
|
Platform::AtomicStore(&_files, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1327,6 +1325,7 @@ FileReadStream* FlaxStorage::OpenFile()
|
|||||||
LOG(Error, "Cannot open Flax Storage file \'{0}\'.", _path);
|
LOG(Error, "Cannot open Flax Storage file \'{0}\'.", _path);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
Platform::InterlockedIncrement(&_files);
|
||||||
|
|
||||||
// Create file reading stream
|
// Create file reading stream
|
||||||
stream = New<FileReadStream>(file);
|
stream = New<FileReadStream>(file);
|
||||||
@@ -1336,6 +1335,13 @@ FileReadStream* FlaxStorage::OpenFile()
|
|||||||
|
|
||||||
bool FlaxStorage::CloseFileHandles()
|
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();
|
PROFILE_CPU();
|
||||||
|
|
||||||
// Note: this is usually called by the content manager when this file is not used or on exit
|
// 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
|
return true; // Failed, someone is still accessing the file
|
||||||
|
|
||||||
// Close file handles (from all threads)
|
// Close file handles (from all threads)
|
||||||
Array<FileReadStream*> streams;
|
Array<FileReadStream*, InlinedAllocation<8>> streams;
|
||||||
_file.GetValues(streams);
|
_file.GetValues(streams);
|
||||||
for (FileReadStream* stream : streams)
|
for (FileReadStream* stream : streams)
|
||||||
{
|
{
|
||||||
@@ -1375,6 +1381,7 @@ bool FlaxStorage::CloseFileHandles()
|
|||||||
Delete(stream);
|
Delete(stream);
|
||||||
}
|
}
|
||||||
_file.Clear();
|
_file.Clear();
|
||||||
|
Platform::AtomicStore(&_files, 0);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,8 +87,9 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
// State
|
// State
|
||||||
int64 _refCount;
|
int64 _refCount = 0;
|
||||||
int64 _chunksLock;
|
int64 _chunksLock = 0;
|
||||||
|
int64 _files = 0;
|
||||||
double _lastRefLostTime;
|
double _lastRefLostTime;
|
||||||
CriticalSection _loadLocker;
|
CriticalSection _loadLocker;
|
||||||
|
|
||||||
@@ -97,7 +98,7 @@ protected:
|
|||||||
Array<FlaxChunk*> _chunks;
|
Array<FlaxChunk*> _chunks;
|
||||||
|
|
||||||
// Metadata
|
// Metadata
|
||||||
uint32 _version;
|
uint32 _version = 0;
|
||||||
String _path;
|
String _path;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
Reference in New Issue
Block a user