diff options
author | Moonchild <moonchild@palemoon.org> | 2021-01-29 14:55:20 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2021-01-29 14:55:20 +0000 |
commit | 745254183c226e5db0caa566ad496d2f0192182e (patch) | |
tree | 467b282ce4e90dba6837dd9d631b6c9082463274 /dom/media/webaudio | |
parent | c76214f0b54cf74b69d0fb4afa0d2eca2e898a98 (diff) | |
parent | e1daeef18312a0cb17eda6bed7f363d8748ed4a3 (diff) | |
download | UXP-745254183c226e5db0caa566ad496d2f0192182e.tar UXP-745254183c226e5db0caa566ad496d2f0192182e.tar.gz UXP-745254183c226e5db0caa566ad496d2f0192182e.tar.lz UXP-745254183c226e5db0caa566ad496d2f0192182e.tar.xz UXP-745254183c226e5db0caa566ad496d2f0192182e.zip |
Merge branch 'master' into release
Diffstat (limited to 'dom/media/webaudio')
-rw-r--r-- | dom/media/webaudio/blink/ReverbInputBuffer.cpp | 21 | ||||
-rw-r--r-- | dom/media/webaudio/blink/ReverbInputBuffer.h | 3 |
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 |