backup thread data race prevention
This commit is contained in:
parent
b8667fc29a
commit
fe10683a70
|
@ -530,18 +530,22 @@ void FurnaceGUI::setFileName(String name) {
|
||||||
if (index>=4095) break;
|
if (index>=4095) break;
|
||||||
}
|
}
|
||||||
ret[index]=0;
|
ret[index]=0;
|
||||||
|
backupLock.lock();
|
||||||
if (GetFullPathNameW(ws.c_str(),4095,ret,NULL)==0) {
|
if (GetFullPathNameW(ws.c_str(),4095,ret,NULL)==0) {
|
||||||
curFileName=name;
|
curFileName=name;
|
||||||
} else {
|
} else {
|
||||||
curFileName=utf16To8(ret);
|
curFileName=utf16To8(ret);
|
||||||
}
|
}
|
||||||
|
backupLock.unlock();
|
||||||
#else
|
#else
|
||||||
char ret[4096];
|
char ret[4096];
|
||||||
|
backupLock.lock();
|
||||||
if (realpath(name.c_str(),ret)==NULL) {
|
if (realpath(name.c_str(),ret)==NULL) {
|
||||||
curFileName=name;
|
curFileName=name;
|
||||||
} else {
|
} else {
|
||||||
curFileName=ret;
|
curFileName=ret;
|
||||||
}
|
}
|
||||||
|
backupLock.unlock();
|
||||||
#endif
|
#endif
|
||||||
updateWindowTitle();
|
updateWindowTitle();
|
||||||
pushRecentFile(curFileName);
|
pushRecentFile(curFileName);
|
||||||
|
@ -2013,7 +2017,9 @@ int FurnaceGUI::save(String path, int dmfVersion) {
|
||||||
#endif
|
#endif
|
||||||
fclose(outFile);
|
fclose(outFile);
|
||||||
w->finish();
|
w->finish();
|
||||||
|
backupLock.lock();
|
||||||
curFileName=path;
|
curFileName=path;
|
||||||
|
backupLock.unlock();
|
||||||
modified=false;
|
modified=false;
|
||||||
updateWindowTitle();
|
updateWindowTitle();
|
||||||
if (!e->getWarnings().empty()) {
|
if (!e->getWarnings().empty()) {
|
||||||
|
@ -2078,7 +2084,9 @@ int FurnaceGUI::load(String path) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
backupLock.lock();
|
||||||
curFileName=path;
|
curFileName=path;
|
||||||
|
backupLock.unlock();
|
||||||
modified=false;
|
modified=false;
|
||||||
curNibble=false;
|
curNibble=false;
|
||||||
orderNibble=false;
|
orderNibble=false;
|
||||||
|
@ -5470,17 +5478,20 @@ bool FurnaceGUI::loop() {
|
||||||
backupTimer=(backupTimer-ImGui::GetIO().DeltaTime);
|
backupTimer=(backupTimer-ImGui::GetIO().DeltaTime);
|
||||||
if (backupTimer<=0) {
|
if (backupTimer<=0) {
|
||||||
backupTask=std::async(std::launch::async,[this]() -> bool {
|
backupTask=std::async(std::launch::async,[this]() -> bool {
|
||||||
|
backupLock.lock();
|
||||||
logV("backupPath: %s",backupPath);
|
logV("backupPath: %s",backupPath);
|
||||||
logV("curFileName: %s",curFileName);
|
logV("curFileName: %s",curFileName);
|
||||||
if (curFileName.find(backupPath)==0) {
|
if (curFileName.find(backupPath)==0) {
|
||||||
logD("backup file open. not saving backup.");
|
logD("backup file open. not saving backup.");
|
||||||
backupTimer=30.0;
|
backupTimer=30.0;
|
||||||
|
backupLock.unlock();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!dirExists(backupPath.c_str())) {
|
if (!dirExists(backupPath.c_str())) {
|
||||||
if (!makeDir(backupPath.c_str())) {
|
if (!makeDir(backupPath.c_str())) {
|
||||||
logW("could not create backup directory!");
|
logW("could not create backup directory!");
|
||||||
backupTimer=30.0;
|
backupTimer=30.0;
|
||||||
|
backupLock.unlock();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5550,6 +5561,7 @@ bool FurnaceGUI::loop() {
|
||||||
}
|
}
|
||||||
logD("backup saved.");
|
logD("backup saved.");
|
||||||
backupTimer=30.0;
|
backupTimer=30.0;
|
||||||
|
backupLock.unlock();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue