Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1553)

Unified Diff: Source/core/platform/audio/AudioDSPKernelProcessor.cpp

Issue 23931002: Fix threading races on AudioDSPKernelProcessor::m_kernels (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/platform/audio/AudioDSPKernelProcessor.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/platform/audio/AudioDSPKernelProcessor.cpp
diff --git a/Source/core/platform/audio/AudioDSPKernelProcessor.cpp b/Source/core/platform/audio/AudioDSPKernelProcessor.cpp
index 0875464968f0ca5e4b05204984eafa73a8117d15..5a8c20f7adb4dff01cba23060d7f7ac3783bd2c2 100644
--- a/Source/core/platform/audio/AudioDSPKernelProcessor.cpp
+++ b/Source/core/platform/audio/AudioDSPKernelProcessor.cpp
@@ -50,6 +50,7 @@ void AudioDSPKernelProcessor::initialize()
if (isInitialized())
return;
+ MutexLocker locker(m_processLock);
ASSERT(!m_kernels.size());
// Create processing kernels, one per channel.
@@ -65,6 +66,7 @@ void AudioDSPKernelProcessor::uninitialize()
if (!isInitialized())
return;
+ MutexLocker locker(m_processLock);
m_kernels.clear();
m_initialized = false;
@@ -81,13 +83,20 @@ void AudioDSPKernelProcessor::process(const AudioBus* source, AudioBus* destinat
return;
}
- bool channelCountMatches = source->numberOfChannels() == destination->numberOfChannels() && source->numberOfChannels() == m_kernels.size();
- ASSERT(channelCountMatches);
- if (!channelCountMatches)
- return;
-
- for (unsigned i = 0; i < m_kernels.size(); ++i)
- m_kernels[i]->process(source->channel(i)->data(), destination->channel(i)->mutableData(), framesToProcess);
+ MutexTryLocker tryLocker(m_processLock);
+ if (tryLocker.locked()) {
+ bool channelCountMatches = source->numberOfChannels() == destination->numberOfChannels() && source->numberOfChannels() == m_kernels.size();
+ ASSERT(channelCountMatches);
+ if (!channelCountMatches)
+ return;
+
+ for (unsigned i = 0; i < m_kernels.size(); ++i)
+ m_kernels[i]->process(source->channel(i)->data(), destination->channel(i)->mutableData(), framesToProcess);
+ } else {
+ // Unfortunately, the kernel is being processed by another thread.
+ // See also ConvolverNode::process().
+ destination->zero();
+ }
}
// Resets filter state
@@ -100,6 +109,7 @@ void AudioDSPKernelProcessor::reset()
// Any processing depending on this value must set it to false at the appropriate time.
m_hasJustReset = true;
+ MutexLocker locker(m_processLock);
for (unsigned i = 0; i < m_kernels.size(); ++i)
m_kernels[i]->reset();
}
@@ -116,12 +126,14 @@ void AudioDSPKernelProcessor::setNumberOfChannels(unsigned numberOfChannels)
double AudioDSPKernelProcessor::tailTime() const
{
+ MutexLocker locker(m_processLock);
Ken Russell (switch to Gerrit) 2013/09/04 18:18:46 I believe this is called on the audio thread and t
haraken 2013/09/04 19:50:05 Done.
// It is expected that all the kernels have the same tailTime.
return !m_kernels.isEmpty() ? m_kernels.first()->tailTime() : 0;
}
double AudioDSPKernelProcessor::latencyTime() const
{
+ MutexLocker locker(m_processLock);
Ken Russell (switch to Gerrit) 2013/09/04 18:18:46 trylock needed here too.
haraken 2013/09/04 19:50:05 Done.
// It is expected that all the kernels have the same latencyTime.
return !m_kernels.isEmpty() ? m_kernels.first()->latencyTime() : 0;
}
« no previous file with comments | « Source/core/platform/audio/AudioDSPKernelProcessor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698