1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-05 14:18:53 +02:00

ODComputeSummaryTask is safe for exceptions; makes no progress then

This commit is contained in:
Paul Licameli 2016-12-26 14:56:32 -05:00
parent 5de19dc952
commit 1a3212611b
2 changed files with 29 additions and 14 deletions

View File

@ -4412,6 +4412,9 @@ void AudacityProject::PopState(const UndoState &state)
computeTask = make_movable<ODComputeSummaryTask>(); computeTask = make_movable<ODComputeSummaryTask>();
odUsed=true; odUsed=true;
} }
// PRL: Is it correct to add all tracks to one task, even if they
// are not partnered channels? Rather than
// make one task for each?
computeTask->AddWaveTrack((WaveTrack*)copyTrack); computeTask->AddWaveTrack((WaveTrack*)copyTrack);
} }
} }

View File

@ -64,32 +64,42 @@ void ODComputeSummaryTask::DoSomeInternal()
return; return;
} }
sampleCount blockStartSample = 0;
sampleCount blockEndSample = 0;
bool success =false;
mBlockFilesMutex.Lock(); mBlockFilesMutex.Lock();
for(size_t i=0; i < mWaveTracks.size() && mBlockFiles.size();i++) for(size_t i=0; i < mWaveTracks.size() && mBlockFiles.size();i++)
{ {
bool success = false;
const auto bf = mBlockFiles[0].lock(); const auto bf = mBlockFiles[0].lock();
sampleCount blockStartSample = 0;
sampleCount blockEndSample = 0;
if(bf) if(bf)
{ {
bf->DoWriteSummary(); // WriteSummary might throw, but this is a worker thread, so stop
// the exceptions here!
success = true; success = true;
try { bf->DoWriteSummary(); }
catch(...) { success = false; }
blockStartSample = bf->GetStart(); blockStartSample = bf->GetStart();
blockEndSample = blockStartSample + bf->GetLength(); blockEndSample = blockStartSample + bf->GetLength();
} }
else else
{ {
success = true;
// The block file disappeared. // The block file disappeared.
//the waveform in the wavetrack now is shorter, so we need to update mMaxBlockFiles //the waveform in the wavetrack now is shorter, so we need to update mMaxBlockFiles
//because now there is less work to do. //because now there is less work to do.
mMaxBlockFiles--; mMaxBlockFiles--;
} }
//take it out of the array - we are done with it. if (success)
mBlockFiles.erase(mBlockFiles.begin()); {
//take it out of the array - we are done with it.
mBlockFiles.erase(mBlockFiles.begin());
}
else
// The task does not make progress
;
//This is a bit of a convenience in case someone tries to terminate the task by closing the trackpanel or window. //This is a bit of a convenience in case someone tries to terminate the task by closing the trackpanel or window.
//ODComputeSummaryTask::Terminate() uses this lock to remove everything, and we don't want it to wait since the UI is being blocked. //ODComputeSummaryTask::Terminate() uses this lock to remove everything, and we don't want it to wait since the UI is being blocked.
@ -97,16 +107,18 @@ void ODComputeSummaryTask::DoSomeInternal()
wxThread::This()->Yield(); wxThread::This()->Yield();
mBlockFilesMutex.Lock(); mBlockFilesMutex.Lock();
//upddate the gui for all associated blocks. It doesn't matter that we're hitting more wavetracks then we should //update the gui for all associated blocks. It doesn't matter that we're hitting more wavetracks then we should
//because this loop runs a number of times equal to the number of tracks, they probably are getting processed in //because this loop runs a number of times equal to the number of tracks, they probably are getting processed in
//the next iteration at the same sample window. //the next iteration at the same sample window.
mWaveTrackMutex.Lock(); if (success && bf) {
for(size_t i=0;i<mWaveTracks.size();i++) mWaveTrackMutex.Lock();
{ for(size_t i=0;i<mWaveTracks.size();i++)
if(success && mWaveTracks[i]) {
mWaveTracks[i]->AddInvalidRegion(blockStartSample,blockEndSample); if(success && mWaveTracks[i])
mWaveTracks[i]->AddInvalidRegion(blockStartSample,blockEndSample);
}
mWaveTrackMutex.Unlock();
} }
mWaveTrackMutex.Unlock();
} }
mBlockFilesMutex.Unlock(); mBlockFilesMutex.Unlock();