mirror of
https://github.com/cookiengineer/audacity
synced 2026-02-05 19:21:59 +01:00
Manage block files with std::shared_ptr, BlockHash stores weak_ptr
This commit is contained in:
@@ -49,8 +49,6 @@ void ODComputeSummaryTask::Terminate()
|
||||
//The terminate block won't allow DoSomeInternal and this method to be run async, so this is thread-safe.
|
||||
//Deref the block files since they are ref'ed when put into the array.
|
||||
mBlockFilesMutex.Lock();
|
||||
for(unsigned int i=0;i<mBlockFiles.size();i++)
|
||||
mBlockFiles[i]->Deref();
|
||||
mBlockFiles.clear();
|
||||
mBlockFilesMutex.Unlock();
|
||||
}
|
||||
@@ -78,7 +76,7 @@ void ODComputeSummaryTask::DoSomeInternal()
|
||||
//first check to see if the ref count is at least 2. It should have one
|
||||
//from when we added it to this instance's mBlockFiles array, and one from
|
||||
//the Wavetrack/sequence. If it doesn't it has been deleted and we should forget it.
|
||||
if(bf->RefCount()>=2)
|
||||
if(bf.use_count() >= 2)
|
||||
{
|
||||
bf->DoWriteSummary();
|
||||
success = true;
|
||||
@@ -93,8 +91,6 @@ void ODComputeSummaryTask::DoSomeInternal()
|
||||
mMaxBlockFiles--;
|
||||
}
|
||||
|
||||
//Release the refcount we placed on it.
|
||||
bf->Deref();
|
||||
//take it out of the array - we are done with it.
|
||||
mBlockFiles.erase(mBlockFiles.begin());
|
||||
|
||||
@@ -169,7 +165,7 @@ void ODComputeSummaryTask::CalculatePercentComplete()
|
||||
///by default left to right, or frome the point the user has clicked.
|
||||
void ODComputeSummaryTask::Update()
|
||||
{
|
||||
std::vector<ODPCMAliasBlockFile*> tempBlocks;
|
||||
std::vector< std::shared_ptr< ODPCMAliasBlockFile > > tempBlocks;
|
||||
|
||||
mWaveTrackMutex.Lock();
|
||||
|
||||
@@ -204,8 +200,8 @@ void ODComputeSummaryTask::Update()
|
||||
const auto &file = block.f;
|
||||
if(file->IsDataAvailable() && !file->IsSummaryAvailable())
|
||||
{
|
||||
file->Ref();
|
||||
ODPCMAliasBlockFile *const odpcmaFile = static_cast<ODPCMAliasBlockFile*>(file);
|
||||
const auto odpcmaFile =
|
||||
std::static_pointer_cast<ODPCMAliasBlockFile>(file);
|
||||
odpcmaFile->SetStart(block.start);
|
||||
odpcmaFile->SetClipOffset((sampleCount)(clip->GetStartTime()*clip->GetRate()));
|
||||
|
||||
@@ -234,11 +230,9 @@ void ODComputeSummaryTask::Update()
|
||||
|
||||
|
||||
///Computes the summary calculation queue order of the blockfiles
|
||||
void ODComputeSummaryTask::OrderBlockFiles(std::vector<ODPCMAliasBlockFile*> &unorderedBlocks)
|
||||
void ODComputeSummaryTask::OrderBlockFiles
|
||||
(std::vector< std::shared_ptr< ODPCMAliasBlockFile > > &unorderedBlocks)
|
||||
{
|
||||
//we are going to take things out of the array. But first deref them since we ref them when we put them in.
|
||||
for(unsigned int i=0;i<mBlockFiles.size();i++)
|
||||
mBlockFiles[i]->Deref();
|
||||
mBlockFiles.clear();
|
||||
//Order the blockfiles into our queue in a fancy convenient way. (this could be user-prefs)
|
||||
//for now just put them in linear. We start the order from the first block that includes the ondemand sample
|
||||
@@ -252,7 +246,7 @@ void ODComputeSummaryTask::OrderBlockFiles(std::vector<ODPCMAliasBlockFile*> &un
|
||||
//check to see if the refcount is at least two before we add it to the list.
|
||||
//There should be one Ref() from the one added by this ODTask, and one from the track.
|
||||
//If there isn't, then the block was deleted for some reason and we should ignore it.
|
||||
if(unorderedBlocks[i]->RefCount()>=2)
|
||||
if(unorderedBlocks[i].use_count() >= 2)
|
||||
{
|
||||
//test if the blockfiles are near the task cursor. we use the last mBlockFiles[0] as our point of reference
|
||||
//and add ones that are closer.
|
||||
@@ -276,7 +270,6 @@ void ODComputeSummaryTask::OrderBlockFiles(std::vector<ODPCMAliasBlockFile*> &un
|
||||
else
|
||||
{
|
||||
//Otherwise, let it be deleted and forget about it.
|
||||
unorderedBlocks[i]->Deref();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user