Diff
Modified: trunk/Source/WTF/ChangeLog (113244 => 113245)
--- trunk/Source/WTF/ChangeLog 2012-04-04 22:06:24 UTC (rev 113244)
+++ trunk/Source/WTF/ChangeLog 2012-04-04 22:13:17 UTC (rev 113245)
@@ -1,3 +1,21 @@
+2012-04-04 Chris Rogers <crog...@google.com>
+
+ Web Audio should use MutexTryLocker class
+ https://bugs.webkit.org/show_bug.cgi?id=83194
+
+ Reviewed by Kenneth Russell.
+
+ Add MutexTryLocker class which can be used as a stack-based object wrapping a Mutex.
+ It will automatically unlock the Mutex in its destructor if the tryLock() succeeded.
+
+ * wtf/ThreadingPrimitives.h:
+ (MutexTryLocker):
+ (WTF::MutexTryLocker::MutexTryLocker):
+ (WTF::MutexTryLocker::~MutexTryLocker):
+ (WTF::MutexTryLocker::locked):
+ Check if the tryLock() on the Mutex succeeded.
+ (WTF):
+
2012-04-04 Kausalya Madhusudhanan <kmadh...@chromium.org>
[Coverity] Address some uninit constructor values.
Modified: trunk/Source/WTF/wtf/ThreadingPrimitives.h (113244 => 113245)
--- trunk/Source/WTF/wtf/ThreadingPrimitives.h 2012-04-04 22:06:24 UTC (rev 113244)
+++ trunk/Source/WTF/wtf/ThreadingPrimitives.h 2012-04-04 22:13:17 UTC (rev 113245)
@@ -97,6 +97,23 @@
typedef Locker<Mutex> MutexLocker;
+class MutexTryLocker {
+ WTF_MAKE_NONCOPYABLE(MutexTryLocker);
+public:
+ WTF_EXPORT_PRIVATE MutexTryLocker(Mutex& mutex) : m_mutex(mutex), m_locked(mutex.tryLock()) { }
+ WTF_EXPORT_PRIVATE ~MutexTryLocker()
+ {
+ if (m_locked)
+ m_mutex.unlock();
+ }
+
+ WTF_EXPORT_PRIVATE bool locked() const { return m_locked; }
+
+private:
+ Mutex& m_mutex;
+ bool m_locked;
+};
+
class ReadWriteLock {
WTF_MAKE_NONCOPYABLE(ReadWriteLock);
public:
@@ -142,6 +159,7 @@
using WTF::Mutex;
using WTF::MutexLocker;
+using WTF::MutexTryLocker;
using WTF::ThreadCondition;
#if OS(WINDOWS)
Modified: trunk/Source/WebCore/ChangeLog (113244 => 113245)
--- trunk/Source/WebCore/ChangeLog 2012-04-04 22:06:24 UTC (rev 113244)
+++ trunk/Source/WebCore/ChangeLog 2012-04-04 22:13:17 UTC (rev 113245)
@@ -1,3 +1,27 @@
+2012-04-04 Chris Rogers <crog...@google.com>
+
+ Web Audio should use MutexTryLocker class
+ https://bugs.webkit.org/show_bug.cgi?id=83194
+
+ Reviewed by Kenneth Russell.
+
+ Switch existing Web Audio code from directly calling tryLock() on a Mutex to use a MutexTryLocker.
+ No new tests since it is a low-level threading primitive and is difficult to test.
+ Existing Web Audio tests continue to test the process() methods affected.
+
+ * Modules/webaudio/AudioBufferSourceNode.cpp:
+ (WebCore::AudioBufferSourceNode::process):
+ * Modules/webaudio/AudioParamTimeline.cpp:
+ (WebCore::AudioParamTimeline::valuesForTimeRange):
+ * Modules/webaudio/ConvolverNode.cpp:
+ (WebCore::ConvolverNode::process):
+ * Modules/webaudio/MediaElementAudioSourceNode.cpp:
+ (WebCore::MediaElementAudioSourceNode::process):
+ * Modules/webaudio/Oscillator.cpp:
+ (WebCore::Oscillator::process):
+ * Modules/webaudio/WaveShaperProcessor.cpp:
+ (WebCore::WaveShaperProcessor::process):
+
2012-04-04 Raphael Kubo da Costa <rak...@webkit.org>
[CSS] Make makevalues.pl and makeprop.pl ignore '#'s.
Modified: trunk/Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp (113244 => 113245)
--- trunk/Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp 2012-04-04 22:06:24 UTC (rev 113244)
+++ trunk/Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp 2012-04-04 22:13:17 UTC (rev 113245)
@@ -98,8 +98,8 @@
}
// The audio thread can't block on this lock, so we call tryLock() instead.
- // Careful - this is a tryLock() and not an autolocker, so we must unlock() before every return.
- if (m_processLock.tryLock()) {
+ MutexTryLocker tryLocker(m_processLock);
+ if (tryLocker.locked()) {
// Check if it's time to start playing.
double sampleRate = this->sampleRate();
size_t quantumStartFrame = context()->currentSampleFrame();
@@ -117,7 +117,6 @@
|| !buffer() || startFrame >= quantumEndFrame) {
// FIXME: can optimize here by propagating silent hint instead of forcing the whole chain to process silence.
outputBus->zero();
- m_processLock.unlock();
return;
}
@@ -159,8 +158,6 @@
finish();
}
-
- m_processLock.unlock();
} else {
// Too bad - the tryLock() failed. We must be in the middle of changing buffers and were already outputting silence anyway.
outputBus->zero();
Modified: trunk/Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp (113244 => 113245)
--- trunk/Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp 2012-04-04 22:06:24 UTC (rev 113244)
+++ trunk/Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp 2012-04-04 22:13:17 UTC (rev 113245)
@@ -143,7 +143,8 @@
float controlRate)
{
// We can't contend the lock in the realtime audio thread.
- if (!m_eventsLock.tryLock()) {
+ MutexTryLocker tryLocker(m_eventsLock);
+ if (!tryLocker.locked()) {
if (values) {
for (unsigned i = 0; i < numberOfValues; ++i)
values[i] = defaultValue;
@@ -152,7 +153,6 @@
}
float value = valuesForTimeRangeImpl(startTime, endTime, defaultValue, values, numberOfValues, sampleRate, controlRate);
- m_eventsLock.unlock();
return value;
}
Modified: trunk/Source/WebCore/Modules/webaudio/ConvolverNode.cpp (113244 => 113245)
--- trunk/Source/WebCore/Modules/webaudio/ConvolverNode.cpp 2012-04-04 22:06:24 UTC (rev 113244)
+++ trunk/Source/WebCore/Modules/webaudio/ConvolverNode.cpp 2012-04-04 22:13:17 UTC (rev 113245)
@@ -68,7 +68,8 @@
ASSERT(outputBus);
// Synchronize with possible dynamic changes to the impulse response.
- if (m_processLock.tryLock()) {
+ MutexTryLocker tryLocker(m_processLock);
+ if (tryLocker.locked()) {
if (!isInitialized() || !m_reverb.get())
outputBus->zero();
else {
@@ -78,8 +79,6 @@
// we keep getting fed silence.
m_reverb->process(input(0)->bus(), outputBus, framesToProcess);
}
-
- m_processLock.unlock();
} else {
// Too bad - the tryLock() failed. We must be in the middle of setting a new impulse response.
outputBus->zero();
Modified: trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.cpp (113244 => 113245)
--- trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.cpp 2012-04-04 22:06:24 UTC (rev 113244)
+++ trunk/Source/WebCore/Modules/webaudio/MediaElementAudioSourceNode.cpp 2012-04-04 22:13:17 UTC (rev 113245)
@@ -114,7 +114,8 @@
// Use a tryLock() to avoid contention in the real-time audio thread.
// If we fail to acquire the lock then the HTMLMediaElement must be in the middle of
// reconfiguring its playback engine, so we output silence in this case.
- if (m_processLock.tryLock()) {
+ MutexTryLocker tryLocker(m_processLock);
+ if (tryLocker.locked()) {
if (AudioSourceProvider* provider = mediaElement()->audioSourceProvider()) {
if (m_multiChannelResampler.get()) {
ASSERT(m_sourceSampleRate != sampleRate());
@@ -129,7 +130,6 @@
// or the stream is not yet available.
outputBus->zero();
}
- m_processLock.unlock();
} else {
// We failed to acquire the lock.
outputBus->zero();
Modified: trunk/Source/WebCore/Modules/webaudio/Oscillator.cpp (113244 => 113245)
--- trunk/Source/WebCore/Modules/webaudio/Oscillator.cpp 2012-04-04 22:06:24 UTC (rev 113244)
+++ trunk/Source/WebCore/Modules/webaudio/Oscillator.cpp 2012-04-04 22:13:17 UTC (rev 113245)
@@ -181,8 +181,8 @@
return;
// The audio thread can't block on this lock, so we call tryLock() instead.
- // Careful - this is a tryLock() and not an autolocker, so we must unlock() before every return.
- if (!m_processLock.tryLock()) {
+ MutexTryLocker tryLocker(m_processLock);
+ if (!tryLocker.locked()) {
// Too bad - the tryLock() failed. We must be in the middle of changing wave-tables.
outputBus->zero();
return;
@@ -191,7 +191,6 @@
// We must access m_waveTable only inside the lock.
if (!m_waveTable.get()) {
outputBus->zero();
- m_processLock.unlock();
return;
}
@@ -263,8 +262,6 @@
}
m_virtualReadIndex = virtualReadIndex;
-
- m_processLock.unlock();
}
void Oscillator::reset()
Modified: trunk/Source/WebCore/Modules/webaudio/WaveShaperProcessor.cpp (113244 => 113245)
--- trunk/Source/WebCore/Modules/webaudio/WaveShaperProcessor.cpp 2012-04-04 22:06:24 UTC (rev 113244)
+++ trunk/Source/WebCore/Modules/webaudio/WaveShaperProcessor.cpp 2012-04-04 22:13:17 UTC (rev 113245)
@@ -64,13 +64,11 @@
}
// The audio thread can't block on this lock, so we call tryLock() instead.
- // Careful - this is a tryLock() and not an autolocker, so we must unlock() before every return.
- if (m_processLock.tryLock()) {
+ MutexTryLocker tryLocker(m_processLock);
+ if (tryLocker.locked()) {
// For each channel of our input, process using the corresponding WaveShaperDSPKernel into the output channel.
for (unsigned i = 0; i < m_kernels.size(); ++i)
m_kernels[i]->process(source->channel(i)->data(), destination->channel(i)->mutableData(), framesToProcess);
-
- m_processLock.unlock();
} else {
// Too bad - the tryLock() failed. We must be in the middle of a setCurve() call.
destination->zero();