mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-31 16:09:28 +02:00
Use RAII idiom for lock and locking mutex in Sequence
This commit is contained in:
parent
13f7d0a81b
commit
6c28276daf
@ -1622,7 +1622,7 @@ bool Sequence::Delete(sampleCount start, sampleCount len)
|
|||||||
//TODO: add a ref-deref mechanism to SeqBlock/BlockArray so we don't have to make this a critical section.
|
//TODO: add a ref-deref mechanism to SeqBlock/BlockArray so we don't have to make this a critical section.
|
||||||
//On-demand threads iterate over the mBlocks and the GUI thread deletes them, so for now put a mutex here over
|
//On-demand threads iterate over the mBlocks and the GUI thread deletes them, so for now put a mutex here over
|
||||||
//both functions,
|
//both functions,
|
||||||
LockDeleteUpdateMutex();
|
DeleteUpdateMutexLocker locker(*this);
|
||||||
|
|
||||||
unsigned int numBlocks = mBlock.size();
|
unsigned int numBlocks = mBlock.size();
|
||||||
|
|
||||||
@ -1661,7 +1661,6 @@ bool Sequence::Delete(sampleCount start, sampleCount len)
|
|||||||
mDirManager->Deref(oldFile);
|
mDirManager->Deref(oldFile);
|
||||||
|
|
||||||
mNumSamples -= len;
|
mNumSamples -= len;
|
||||||
UnlockDeleteUpdateMutex();
|
|
||||||
|
|
||||||
return ConsistencyCheck(wxT("Delete - branch one"));
|
return ConsistencyCheck(wxT("Delete - branch one"));
|
||||||
}
|
}
|
||||||
@ -1786,7 +1785,6 @@ bool Sequence::Delete(sampleCount start, sampleCount len)
|
|||||||
// Update total number of samples and do a consistency check.
|
// Update total number of samples and do a consistency check.
|
||||||
mNumSamples -= len;
|
mNumSamples -= len;
|
||||||
|
|
||||||
UnlockDeleteUpdateMutex();
|
|
||||||
return ConsistencyCheck(wxT("Delete - branch two"));
|
return ConsistencyCheck(wxT("Delete - branch two"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,6 +194,21 @@ class Sequence: public XMLTagHandler {
|
|||||||
void LockDeleteUpdateMutex(){mDeleteUpdateMutex.Lock();}
|
void LockDeleteUpdateMutex(){mDeleteUpdateMutex.Lock();}
|
||||||
void UnlockDeleteUpdateMutex(){mDeleteUpdateMutex.Unlock();}
|
void UnlockDeleteUpdateMutex(){mDeleteUpdateMutex.Unlock();}
|
||||||
|
|
||||||
|
// RAII idiom wrapping the functions above
|
||||||
|
struct DeleteUpdateMutexLocker {
|
||||||
|
DeleteUpdateMutexLocker(Sequence &sequence)
|
||||||
|
: mSequence(sequence)
|
||||||
|
{
|
||||||
|
mSequence.LockDeleteUpdateMutex();
|
||||||
|
}
|
||||||
|
~DeleteUpdateMutexLocker()
|
||||||
|
{
|
||||||
|
mSequence.UnlockDeleteUpdateMutex();
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
Sequence &mSequence;
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -190,7 +190,7 @@ void ODComputeSummaryTask::Update()
|
|||||||
seq = clip->GetSequence();
|
seq = clip->GetSequence();
|
||||||
//This lock may be way too big since the whole file is one sequence.
|
//This lock may be way too big since the whole file is one sequence.
|
||||||
//TODO: test for large files and find a way to break it down.
|
//TODO: test for large files and find a way to break it down.
|
||||||
seq->LockDeleteUpdateMutex();
|
Sequence::DeleteUpdateMutexLocker locker(*seq);
|
||||||
|
|
||||||
//See Sequence::Delete() for why need this for now..
|
//See Sequence::Delete() for why need this for now..
|
||||||
//We don't need the mBlockFilesMutex here because it is only for the vector list.
|
//We don't need the mBlockFilesMutex here because it is only for the vector list.
|
||||||
@ -223,7 +223,6 @@ void ODComputeSummaryTask::Update()
|
|||||||
tempBlocks.insert(tempBlocks.begin() + insertCursor++, odpcmaFile);
|
tempBlocks.insert(tempBlocks.begin() + insertCursor++, odpcmaFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
seq->UnlockDeleteUpdateMutex();
|
|
||||||
node = node->GetNext();
|
node = node->GetNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user