Bug 1078451 - Accept a free function in ThreadSharedFloatArrayBufferList::SetData. r=jesup

This commit is contained in:
Guilherme Goncalves 2014-10-07 10:03:00 +02:00
parent 5d68c19c22
commit c4810bf94e
4 changed files with 22 additions and 11 deletions

View File

@ -226,7 +226,7 @@ StealJSArrayDataIntoThreadSharedFloatArrayBufferList(JSContext* aJSContext,
? (uint8_t*) JS_StealArrayBufferContents(aJSContext, arrayBuffer)
: nullptr;
if (stolenData) {
result->SetData(i, stolenData, reinterpret_cast<float*>(stolenData));
result->SetData(i, stolenData, js_free, reinterpret_cast<float*>(stolenData));
} else {
return nullptr;
}

View File

@ -38,12 +38,16 @@ public:
}
struct Storage {
Storage()
{
mDataToFree = nullptr;
mSampleData = nullptr;
Storage() :
mDataToFree(nullptr),
mFree(nullptr),
mSampleData(nullptr)
{}
~Storage() {
if (mFree) {
mFree(mDataToFree);
} else { MOZ_ASSERT(!mDataToFree); }
}
~Storage() { free(mDataToFree); }
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
{
// NB: mSampleData might not be owned, if it is it just points to
@ -51,6 +55,7 @@ public:
return aMallocSizeOf(mDataToFree);
}
void* mDataToFree;
void (*mFree)(void*);
const float* mSampleData;
};
@ -67,11 +72,17 @@ public:
* Call this only during initialization, before the object is handed to
* any other thread.
*/
void SetData(uint32_t aIndex, void* aDataToFree, const float* aData)
void SetData(uint32_t aIndex, void* aDataToFree, void (*aFreeFunc)(void*), const float* aData)
{
Storage* s = &mContents[aIndex];
free(s->mDataToFree);
if (s->mFree) {
s->mFree(s->mDataToFree);
} else {
MOZ_ASSERT(!s->mDataToFree);
}
s->mDataToFree = aDataToFree;
s->mFree = aFreeFunc;
s->mSampleData = aData;
}

View File

@ -258,7 +258,7 @@ ConvolverNode::SetBuffer(JSContext* aCx, AudioBuffer* aBuffer, ErrorResult& aRv)
for (uint32_t i = 0; i < data->GetChannels(); ++i) {
PodCopy(channelData + length * i, data->GetData(i), mBuffer->Length());
PodZero(channelData + length * i + mBuffer->Length(), WEBAUDIO_BLOCK_SIZE - mBuffer->Length());
paddedBuffer->SetData(i, (i == 0) ? channelData : nullptr, channelData);
paddedBuffer->SetData(i, (i == 0) ? channelData : nullptr, free, channelData);
}
data = paddedBuffer;
}

View File

@ -38,9 +38,9 @@ PeriodicWave::PeriodicWave(AudioContext* aContext,
return;
}
PodCopy(buffer, aRealData, aLength);
mCoefficients->SetData(0, buffer, buffer);
mCoefficients->SetData(0, buffer, free, buffer);
PodCopy(buffer+aLength, aImagData, aLength);
mCoefficients->SetData(1, nullptr, buffer+aLength);
mCoefficients->SetData(1, nullptr, free, buffer+aLength);
}
size_t