Merge pull request #4005 from EmptyChaos/blockcache-bug

SectorReader: Minor cache bias bug
This commit is contained in:
Pierre Bourdon 2016-07-13 12:11:19 +02:00 committed by GitHub
commit f4d2626d2b
2 changed files with 11 additions and 8 deletions

View File

@ -57,12 +57,15 @@ SectorReader::Cache* SectorReader::GetEmptyCacheLine()
{ {
Cache* oldest = &m_cache[0]; Cache* oldest = &m_cache[0];
// Find the Least Recently Used cache line to replace. // Find the Least Recently Used cache line to replace.
for (auto& cache_entry : m_cache) std::for_each(m_cache.begin() + 1, m_cache.end(), [&](Cache& line) {
{ if (line.IsLessRecentlyUsedThan(*oldest))
if (cache_entry.IsLessRecentlyUsedThan(*oldest)) {
oldest = &cache_entry; oldest->ShiftLRU();
cache_entry.ShiftLRU(); oldest = &line;
} return;
}
line.ShiftLRU();
});
oldest->Reset(); oldest->Reset();
return oldest; return oldest;
} }

View File

@ -138,9 +138,9 @@ bool DriveReader::ReadMultipleAlignedBlocks(u64 block_num, u64 num_blocks, u8* o
#ifdef _WIN32 #ifdef _WIN32
LARGE_INTEGER offset; LARGE_INTEGER offset;
offset.QuadPart = GetSectorSize() * block_num; offset.QuadPart = GetSectorSize() * block_num;
SetFilePointerEx(m_disc_handle, offset, nullptr, FILE_BEGIN);
DWORD bytes_read; DWORD bytes_read;
if (!ReadFile(m_disc_handle, out_ptr, static_cast<DWORD>(GetSectorSize() * num_blocks), if (!SetFilePointerEx(m_disc_handle, offset, nullptr, FILE_BEGIN) ||
!ReadFile(m_disc_handle, out_ptr, static_cast<DWORD>(GetSectorSize() * num_blocks),
&bytes_read, nullptr)) &bytes_read, nullptr))
{ {
PanicAlertT("Disc Read Error"); PanicAlertT("Disc Read Error");