Bug 848954 - Part 13 - Add an RAII class to ensure another thread is not in the audio callback when shutting down. r=roc

This commit is contained in:
Paul Adenot 2014-08-26 17:01:35 +02:00
Родитель b1ff1946e0
Коммит d73a6771b0
3 изменённых файлов: 35 добавлений и 0 удалений

Просмотреть файл

@ -551,11 +551,30 @@ AudioCallbackDriver::StateCallback_s(cubeb_stream* aStream, void * aUser,
driver->StateCallback(aState);
}
bool AudioCallbackDriver::InCallback() {
MonitorAutoLock mon(mGraphImpl->GetMonitor());
return mInCallback;
}
AudioCallbackDriver::AutoInCallback::AutoInCallback(AudioCallbackDriver* aDriver)
: mDriver(aDriver)
{
MonitorAutoLock mon(mDriver->mGraphImpl->GetMonitor());
mDriver->mInCallback = true;
}
AudioCallbackDriver::AutoInCallback::~AutoInCallback() {
MonitorAutoLock mon(mDriver->mGraphImpl->GetMonitor());
mDriver->mInCallback = false;
}
long
AudioCallbackDriver::DataCallback(AudioDataValue* aBuffer, long aFrames)
{
bool stillProcessing;
DebugOnly<AutoInCallback> aic(this);
if (mStateComputedTime == 0) {
MonitorAutoLock mon(mGraphImpl->GetMonitor());
// Because this function is called during cubeb_stream_init (to prefill the

Просмотреть файл

@ -143,6 +143,8 @@ public:
MOZ_CRASH("This is not an Audio GraphDriver!");
}
bool InCallback();
virtual AudioCallbackDriver* AsAudioCallbackDriver() {
return nullptr;
}
@ -439,6 +441,16 @@ private:
* This is synchronized by the Graph's monitor.
* */
bool mStarted;
/* This can only be accessed with the graph's monitor held. */
bool mInCallback;
struct AutoInCallback
{
AutoInCallback(AudioCallbackDriver* aDriver);
~AutoInCallback();
AudioCallbackDriver* mDriver;
};
};
}

Просмотреть файл

@ -1490,6 +1490,10 @@ public:
NS_ASSERTION(mGraph->mDetectedNotRunning,
"We should know the graph thread control loop isn't running!");
if (mGraph->CurrentDriver()->AsAudioCallbackDriver()) {
MOZ_ASSERT(!mGraph->CurrentDriver()->AsAudioCallbackDriver()->InCallback());
}
STREAM_LOG(PR_LOG_DEBUG, ("Shutting drown graph %p", mGraph));
// mGraph's thread is not running so it's OK to do whatever here