Fixed windows deadlocks, performance is shit tho
This commit is contained in:
@@ -165,7 +165,8 @@ void SweepstoreConcurrencyHeader::initialise(int concurrentWorkers) {
|
||||
void SweepstoreWorkerTicket::write(SweepstoreWorkerTicketSnapshot &snapshot) {
|
||||
RandomAccessMemory buffer;
|
||||
|
||||
uint64_t offset = getOffset();
|
||||
SweepstoreFileLock lock(file.getPath(), 0, 0, SweepstoreFileLock::Mode::Exclusive);
|
||||
SweepstoreFileLock::Scoped scopedLock(lock);
|
||||
|
||||
buffer.setPositionSync(0);
|
||||
buffer.writeIntSync(snapshot.identifier, 4);
|
||||
@@ -187,20 +188,23 @@ void SweepstoreWorkerTicket::write(SweepstoreWorkerTicketSnapshot &snapshot) {
|
||||
char* dataPtr = reinterpret_cast<char*>(data.data());
|
||||
|
||||
// Write to file
|
||||
file.writeSeek(offset);
|
||||
file.writeSeek(getOffset());
|
||||
file.writeBytes(dataPtr, data.size());
|
||||
file.flush();
|
||||
}
|
||||
|
||||
bool SweepstoreWorkerTicket::writable() {
|
||||
return true;
|
||||
SweepstoreFileLock lock(file.getPath(), 0, 0, SweepstoreFileLock::Mode::Exclusive);
|
||||
return lock.isLocked() == false;
|
||||
}
|
||||
|
||||
SweepstoreWorkerTicketSnapshot SweepstoreWorkerTicket::snapshot() {
|
||||
uint64_t offset = getOffset();
|
||||
file.readSeek(offset);
|
||||
SweepstoreFileLock lock(file.getPath(), 0, 0, SweepstoreFileLock::Mode::Shared);
|
||||
lock.lock();
|
||||
file.readSeek(getOffset());
|
||||
std::unique_ptr<char[]> buffer(new char[TICKET_SIZE]);
|
||||
file.readBytes(buffer.get(), TICKET_SIZE);
|
||||
lock.unlock();
|
||||
RandomAccessMemory ram(reinterpret_cast<uint8_t*>(buffer.get()), TICKET_SIZE);
|
||||
|
||||
SweepstoreWorkerTicketSnapshot snapshot;
|
||||
|
||||
@@ -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