Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update disk.hpp - Flush disk cache instantly to avoid stuck in Windows #226

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/disk.hpp
Expand Up @@ -206,9 +206,6 @@ struct FileDisk {
}
amtwritten =
::fwrite(reinterpret_cast<const char *>(memcache), sizeof(uint8_t), length, f_);
#ifdef _WIN32
_commit(_fileno(f_));
#endif
writePos = begin + amtwritten;
if (writePos > writeMax)
writeMax = writePos;
Expand All @@ -219,6 +216,14 @@ struct FileDisk {
std::this_thread::sleep_for(5min);
}
} while (amtwritten != length);
#ifdef _WIN32
// Flush Windows Cache after few cycles
flush_cyclecount += 1;
if (flush_cyclecount >= flush_cyclelimit){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes more sense. However, if this turns out to give some people worse performance, they really should have a configuration option to disable it or change this limit.

The limit should probably be specified in number-of-bytes written to the file too.

flush_cyclecount = 0;
_commit(_fileno(f_));
}
#endif
}

std::string GetFileName() { return filename_.string(); }
Expand All @@ -236,6 +241,12 @@ struct FileDisk {
uint64_t readPos = 0;
uint64_t writePos = 0;
uint64_t writeMax = 0;

#ifdef _WIN32
uint8_t flush_cyclelimit = 50;
uint8_t flush_cyclecount = 0;
#endif

bool bReading = true;

fs::path filename_;
Expand Down