one more race condition fix

This commit is contained in:
tildearrow 2022-03-21 17:56:48 -05:00
parent 80927b80b1
commit 6050fc7208

View file

@ -614,9 +614,11 @@ void DivEngine::createNew(const int* description) {
void DivEngine::changeSystem(int index, DivSystem which) { void DivEngine::changeSystem(int index, DivSystem which) {
quitDispatch(); quitDispatch();
isBusy.lock(); isBusy.lock();
saveLock.lock();
song.system[index]=which; song.system[index]=which;
song.systemFlags[index]=0; song.systemFlags[index]=0;
recalcChans(); recalcChans();
saveLock.unlock();
isBusy.unlock(); isBusy.unlock();
initDispatch(); initDispatch();
isBusy.lock(); isBusy.lock();
@ -637,11 +639,13 @@ bool DivEngine::addSystem(DivSystem which) {
} }
quitDispatch(); quitDispatch();
isBusy.lock(); isBusy.lock();
saveLock.lock();
song.system[song.systemLen]=which; song.system[song.systemLen]=which;
song.systemVol[song.systemLen]=64; song.systemVol[song.systemLen]=64;
song.systemPan[song.systemLen]=0; song.systemPan[song.systemLen]=0;
song.systemFlags[song.systemLen++]=0; song.systemFlags[song.systemLen++]=0;
recalcChans(); recalcChans();
saveLock.unlock();
isBusy.unlock(); isBusy.unlock();
initDispatch(); initDispatch();
isBusy.lock(); isBusy.lock();
@ -662,12 +666,14 @@ bool DivEngine::removeSystem(int index) {
} }
quitDispatch(); quitDispatch();
isBusy.lock(); isBusy.lock();
saveLock.lock();
song.system[index]=DIV_SYSTEM_NULL; song.system[index]=DIV_SYSTEM_NULL;
song.systemLen--; song.systemLen--;
for (int i=index; i<song.systemLen; i++) { for (int i=index; i<song.systemLen; i++) {
song.system[i]=song.system[i+1]; song.system[i]=song.system[i+1];
} }
recalcChans(); recalcChans();
saveLock.unlock();
isBusy.unlock(); isBusy.unlock();
initDispatch(); initDispatch();
isBusy.lock(); isBusy.lock();