diff options
Diffstat (limited to 'dom/media/webaudio/blink/ReverbInputBuffer.cpp')
-rw-r--r-- | dom/media/webaudio/blink/ReverbInputBuffer.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/dom/media/webaudio/blink/ReverbInputBuffer.cpp b/dom/media/webaudio/blink/ReverbInputBuffer.cpp index 8221f8151..6b8e642d2 100644 --- a/dom/media/webaudio/blink/ReverbInputBuffer.cpp +++ b/dom/media/webaudio/blink/ReverbInputBuffer.cpp @@ -42,19 +42,20 @@ ReverbInputBuffer::ReverbInputBuffer(size_t length) void ReverbInputBuffer::write(const float* sourceP, size_t numberOfFrames) { - size_t bufferLength = m_buffer.Length(); - bool isCopySafe = m_writeIndex + numberOfFrames <= bufferLength; - MOZ_ASSERT(isCopySafe); - if (!isCopySafe) - return; + // m_writeIndex is atomic and checked by other threads, so only touch + // it at the start and end. + size_t index = m_writeIndex; + + size_t bufferLength = m_buffer.Length(); + size_t newIndex = index + numberOfFrames; - memcpy(m_buffer.Elements() + m_writeIndex, sourceP, sizeof(float) * numberOfFrames); + MOZ_RELEASE_ASSERT(newIndex <= bufferLength); - m_writeIndex += numberOfFrames; - MOZ_ASSERT(m_writeIndex <= bufferLength); + memcpy(m_buffer.Elements() + index, sourceP, sizeof(float) * numberOfFrames); - if (m_writeIndex >= bufferLength) - m_writeIndex = 0; + if (newIndex >= bufferLength) { + m_writeIndex = 0; + } } float* ReverbInputBuffer::directReadFrom(int* readIndex, size_t numberOfFrames) |