Fixed windows deadlocks, performance is shit tho
This commit is contained in:
@@ -86,10 +86,27 @@ void SweepstoreFileHandle::flush() {
|
||||
unrealHandle->Flush();
|
||||
}
|
||||
#else
|
||||
// Windows-specific implementation for guaranteed flush to disk
|
||||
auto& stream = getThreadStream();
|
||||
stream.flush();
|
||||
// On Windows, also sync to ensure data hits disk
|
||||
stream.sync();
|
||||
|
||||
// On Windows, also call sync to push to OS buffers
|
||||
// Then open a Windows HANDLE to the same file and call FlushFileBuffers
|
||||
// This is more reliable than trying to extract the HANDLE from fstream
|
||||
HANDLE h = CreateFileA(
|
||||
path.c_str(),
|
||||
GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL
|
||||
);
|
||||
|
||||
if (h != INVALID_HANDLE_VALUE) {
|
||||
FlushFileBuffers(h);
|
||||
CloseHandle(h);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -106,15 +123,12 @@ void SweepstoreFileHandle::readSeek(std::streampos pos, std::ios::seekdir dir) {
|
||||
unrealHandle->SeekFromEnd(unrealPos);
|
||||
}
|
||||
#else
|
||||
// Windows
|
||||
// Windows - simplified to only seek read pointer
|
||||
auto& stream = getThreadStream();
|
||||
// On Windows, flush and sync to disk, then invalidate buffers
|
||||
stream.flush();
|
||||
stream.sync();
|
||||
stream.clear();
|
||||
// Sync both pointers to same position
|
||||
stream.seekp(pos, dir);
|
||||
stream.seekg(pos, dir);
|
||||
if (stream.fail()) {
|
||||
stream.clear();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -124,11 +138,12 @@ void SweepstoreFileHandle::writeSeek(std::streampos pos, std::ios::seekdir dir)
|
||||
// Same as readSeek for Unreal
|
||||
readSeek(pos, dir);
|
||||
#else
|
||||
// Windows
|
||||
// Windows - simplified to only seek write pointer
|
||||
auto& stream = getThreadStream();
|
||||
stream.flush();
|
||||
stream.sync();
|
||||
stream.seekp(pos, dir);
|
||||
if (stream.fail()) {
|
||||
stream.clear();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -140,10 +155,6 @@ void SweepstoreFileHandle::readBytes(char* buffer, std::streamsize size) {
|
||||
// Windows
|
||||
auto& stream = getThreadStream();
|
||||
stream.read(buffer, size);
|
||||
// Check for read errors on Windows
|
||||
if (stream.fail() && !stream.eof()) {
|
||||
stream.clear();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -156,10 +167,6 @@ void SweepstoreFileHandle::writeBytes(const char* buffer, std::streamsize size)
|
||||
// Windows
|
||||
auto& stream = getThreadStream();
|
||||
stream.write(buffer, size);
|
||||
// Check for write errors on Windows
|
||||
if (stream.fail()) {
|
||||
stream.clear();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif // _WIN32 || WITH_UNREAL
|
||||
Reference in New Issue
Block a user