mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
Io: Allow early cancel of CRC calculation.
This commit is contained in:
parent
25b0be7fe3
commit
872fecd8ed
@ -50,11 +50,13 @@ BlockDevice *constructBlockDevice(FileLoader *fileLoader) {
|
||||
return new FileBlockDevice(fileLoader);
|
||||
}
|
||||
|
||||
u32 BlockDevice::CalculateCRC() {
|
||||
u32 BlockDevice::CalculateCRC(volatile bool *cancel) {
|
||||
u32 crc = crc32(0, Z_NULL, 0);
|
||||
|
||||
u8 block[2048];
|
||||
for (u32 i = 0; i < GetNumBlocks(); ++i) {
|
||||
if (cancel && *cancel)
|
||||
return 0;
|
||||
if (!ReadBlock(i, block, true)) {
|
||||
ERROR_LOG(FILESYS, "Failed to read block for CRC");
|
||||
return 0;
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
virtual u32 GetNumBlocks() = 0;
|
||||
virtual bool IsDisc() = 0;
|
||||
|
||||
u32 CalculateCRC();
|
||||
u32 CalculateCRC(volatile bool *cancel = nullptr);
|
||||
void NotifyReadError();
|
||||
|
||||
protected:
|
||||
|
@ -103,6 +103,7 @@ namespace Reporting
|
||||
static std::string crcFilename;
|
||||
static std::map<std::string, u32> crcResults;
|
||||
static volatile bool crcPending = false;
|
||||
static volatile bool crcCancel = false;
|
||||
static std::thread crcThread;
|
||||
|
||||
static int CalculateCRCThread() {
|
||||
@ -114,7 +115,7 @@ namespace Reporting
|
||||
|
||||
u32 crc = 0;
|
||||
if (blockDevice) {
|
||||
crc = blockDevice->CalculateCRC();
|
||||
crc = blockDevice->CalculateCRC(&crcCancel);
|
||||
}
|
||||
|
||||
delete blockDevice;
|
||||
@ -145,6 +146,7 @@ namespace Reporting
|
||||
|
||||
crcFilename = gamePath;
|
||||
crcPending = true;
|
||||
crcCancel = false;
|
||||
crcThread = std::thread(CalculateCRCThread);
|
||||
}
|
||||
|
||||
@ -179,6 +181,7 @@ namespace Reporting
|
||||
|
||||
static void PurgeCRC() {
|
||||
std::unique_lock<std::mutex> guard(crcLock);
|
||||
crcCancel = true;
|
||||
while (crcPending) {
|
||||
crcCond.wait(guard);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user