summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dom/media/webaudio/blink/ReverbInputBuffer.cpp21
-rw-r--r--dom/media/webaudio/blink/ReverbInputBuffer.h3
2 files changed, 13 insertions, 11 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)
diff --git a/dom/media/webaudio/blink/ReverbInputBuffer.h b/dom/media/webaudio/blink/ReverbInputBuffer.h
index 906021c0d..f51aa3091 100644
--- a/dom/media/webaudio/blink/ReverbInputBuffer.h
+++ b/dom/media/webaudio/blink/ReverbInputBuffer.h
@@ -30,6 +30,7 @@
#define ReverbInputBuffer_h
#include "nsTArray.h"
+#include "mozilla/Atomics.h"
#include "mozilla/MemoryReporting.h"
namespace WebCore {
@@ -63,7 +64,7 @@ public:
private:
nsTArray<float> m_buffer;
- size_t m_writeIndex;
+ mozilla::Atomic<size_t, mozilla::ReleaseAcquire> m_writeIndex;
};
} // namespace WebCore