Bug 868409 - ScriptProcessorNode's playing ref should remain active as long as there are outstanding connections; r=roc

This commit is contained in:
Ehsan Akhgari 2013-05-03 10:59:41 -04:00
parent c3368424ee
commit 79f926cc63
2 changed files with 40 additions and 2 deletions

View File

@ -59,6 +59,44 @@ private:
bool mHeld;
};
template<class T>
class SelfCountedReference {
public:
SelfCountedReference() : mRefCnt(0) {}
~SelfCountedReference()
{
NS_ASSERTION(mRefCnt == 0, "Forgot to drop the self reference?");
}
void Take(T* t)
{
if (mRefCnt++ == 0) {
t->AddRef();
}
}
void Drop(T* t)
{
if (mRefCnt > 0) {
--mRefCnt;
if (mRefCnt == 0) {
t->Release();
}
}
}
void ForceDrop(T* t)
{
if (mRefCnt > 0) {
mRefCnt = 0;
t->Release();
}
}
operator bool() const { return mRefCnt > 0; }
private:
nsrefcnt mRefCnt;
};
/**
* The DOM object representing a Web Audio AudioNode.
*

View File

@ -82,14 +82,14 @@ public:
void Stop()
{
mPlayingRef.Drop(this);
mPlayingRef.ForceDrop(this);
}
private:
nsAutoPtr<SharedBuffers> mSharedBuffers;
const uint32_t mBufferSize;
const uint32_t mNumberOfOutputChannels;
SelfReference<ScriptProcessorNode> mPlayingRef; // a reference to self while planing
SelfCountedReference<ScriptProcessorNode> mPlayingRef; // a reference to self while planing
};
}