Skip to content

Commit

Permalink
Bug 1062533 - part 6 - change ReverbConvolver to use mozilla locking …
Browse files Browse the repository at this point in the history
…constructs; r=padenot

We are cargo-culting ipc/chromium/ code for this, and ReverbConvolver is
essentially the only outside consumer of Chromium IPC locks at this
point.
  • Loading branch information
froydnj committed Jan 9, 2019
1 parent 84a074e commit a299b06
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
21 changes: 10 additions & 11 deletions dom/media/webaudio/blink/ReverbConvolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ReverbConvolver::ReverbConvolver(const float* impulseResponseData,
m_accumulationBuffer(impulseResponseLength + WEBAUDIO_BLOCK_SIZE),
m_inputBuffer(InputBufferSize),
m_backgroundThread("ConvolverWorker"),
m_backgroundThreadCondition(&m_backgroundThreadLock),
m_backgroundThreadMonitor("ConvolverMonitor"),
m_useBackgroundThreads(useBackgroundThreads),
m_wantsToExit(false),
m_moreInputBuffered(false) {
Expand Down Expand Up @@ -166,9 +166,9 @@ ReverbConvolver::~ReverbConvolver() {

// Wake up thread so it can return
{
AutoLock locker(m_backgroundThreadLock);
MonitorAutoLock locker(m_backgroundThreadMonitor);
m_moreInputBuffered = true;
m_backgroundThreadCondition.Signal();
m_backgroundThreadMonitor.Notify();
}

m_backgroundThread.Stop();
Expand Down Expand Up @@ -199,8 +199,7 @@ size_t ReverbConvolver::sizeOfIncludingThis(

// Possible future measurements:
// - m_backgroundThread
// - m_backgroundThreadLock
// - m_backgroundThreadCondition
// - m_backgroundThreadMonitor
return amount;
}

Expand All @@ -209,9 +208,9 @@ void ReverbConvolver::backgroundThreadEntry() {
// Wait for realtime thread to give us more input
m_moreInputBuffered = false;
{
AutoLock locker(m_backgroundThreadLock);
MonitorAutoLock locker(m_backgroundThreadMonitor);
while (!m_moreInputBuffered && !m_wantsToExit)
m_backgroundThreadCondition.Wait();
m_backgroundThreadMonitor.Wait();
}

// Process all of the stages until their read indices reach the input
Expand Down Expand Up @@ -251,17 +250,17 @@ void ReverbConvolver::process(const float* sourceChannelData,

// Now that we've buffered more input, wake up our background thread.

// Not using a MutexLocker looks strange, but we use a tryLock() instead
// Not using a MonitorAutoLock looks strange, but we use a TryLock() instead
// because this is run on the real-time thread where it is a disaster for the
// lock to be contended (causes audio glitching). It's OK if we fail to
// signal from time to time, since we'll get to it the next time we're called.
// We're called repeatedly and frequently (around every 3ms). The background
// thread is processing well into the future and has a considerable amount of
// leeway here...
if (m_backgroundThreadLock.Try()) {
if (m_backgroundThreadMonitor.TryLock()) {
m_moreInputBuffered = true;
m_backgroundThreadCondition.Signal();
m_backgroundThreadLock.Release();
m_backgroundThreadMonitor.Notify();
m_backgroundThreadMonitor.Unlock();
}
}

Expand Down
6 changes: 2 additions & 4 deletions dom/media/webaudio/blink/ReverbConvolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
#include "ReverbInputBuffer.h"
#include "nsAutoPtr.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/Monitor.h"
#ifdef LOG
#undef LOG
#endif
#include "base/condition_variable.h"
#include "base/lock.h"
#include "base/thread.h"

namespace WebCore {
Expand Down Expand Up @@ -80,8 +79,7 @@ class ReverbConvolver {

// Background thread and synchronization
base::Thread m_backgroundThread;
Lock m_backgroundThreadLock;
ConditionVariable m_backgroundThreadCondition;
mozilla::Monitor m_backgroundThreadMonitor;
bool m_useBackgroundThreads;
bool m_wantsToExit;
bool m_moreInputBuffered;
Expand Down

0 comments on commit a299b06

Please sign in to comment.