1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-15 00:51:21 +01:00

Manage block files with std::shared_ptr, BlockHash stores weak_ptr

This commit is contained in:
Paul Licameli
2016-08-16 10:52:43 -04:00
parent 84ccdca5c3
commit 8b72bd2f92
14 changed files with 51 additions and 230 deletions

View File

@@ -74,33 +74,6 @@ ODPCMAliasBlockFile::~ODPCMAliasBlockFile()
{
}
/// Increases the reference count of this block by one. Only
/// DirManager should call this method.
/// This method has been overidden to be threadsafe. It is important especially
/// if two blockfiles deref at the same time resulting in a double deletion of the file
void ODPCMAliasBlockFile::Ref() const
{
mRefMutex.Lock();
BlockFile::Ref();
mRefMutex.Unlock();
}
/// Decreases the reference count of this block by one. If this
/// causes the count to become zero, deletes the associated disk
/// file and deletes this object
bool ODPCMAliasBlockFile::Deref() const
{
bool ret;
mDerefMutex.Lock();
ret = BlockFile::Deref();
if(!ret)
{
//Deref returns true when deleted, in which case we should not be touching instance variables, or ever calling this function again.
mDerefMutex.Unlock();
}
return ret;
}
//Check to see if we have the file for these calls.

View File

@@ -143,13 +143,6 @@ protected:
sampleFormat format, ArrayOf<char> &cleanup) override;
private:
//Thread-safe versions
void Ref() const override;
bool Deref() const override;
//needed for Ref/Deref access.
friend class DirManager;
friend class ODComputeSummaryTask;
friend class ODDecodeTask;
ODLock mWriteSummaryMutex;
@@ -162,11 +155,6 @@ protected:
//lock the read data - libsndfile can't handle two reads at once?
mutable ODLock mReadDataMutex;
//lock the Ref counting
mutable ODLock mDerefMutex;
mutable ODLock mRefMutex;
mutable ODLock mSummaryAvailableMutex;
bool mSummaryAvailable;
bool mSummaryBeingComputed;