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

Unified Diff: media/audio/sounds/audio_stream_handler.cc

Issue 348843004: Fix potential deadlock situation for ChromeOS sounds. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove suppressions. Created 6 years, 6 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 | « base/debug/tsan_suppressions.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/sounds/audio_stream_handler.cc
diff --git a/media/audio/sounds/audio_stream_handler.cc b/media/audio/sounds/audio_stream_handler.cc
index 2a08b29d71ee5142950b9386220db0f2ddb2b069..645fcb366a3fe8d6efa2faf12a366c8fdff102c6 100644
--- a/media/audio/sounds/audio_stream_handler.cc
+++ b/media/audio/sounds/audio_stream_handler.cc
@@ -37,12 +37,11 @@ class AudioStreamHandler::AudioStreamContainer
: public AudioOutputStream::AudioSourceCallback {
public:
AudioStreamContainer(const WavAudioHandler& wav_audio)
- : stream_(NULL),
- wav_audio_(wav_audio),
+ : started_(false),
+ stream_(NULL),
cursor_(0),
- started_(false),
- delayed_stop_posted_(false) {
- }
+ delayed_stop_posted_(false),
+ wav_audio_(wav_audio) {}
virtual ~AudioStreamContainer() {
DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread());
@@ -58,8 +57,8 @@ class AudioStreamHandler::AudioStreamContainer
p.sample_rate(),
p.bits_per_sample(),
kDefaultFrameCount);
- stream_ = AudioManager::Get()->MakeAudioOutputStreamProxy(
- params, std::string());
+ stream_ = AudioManager::Get()->MakeAudioOutputStreamProxy(params,
+ std::string());
if (!stream_ || !stream_->Open()) {
LOG(ERROR) << "Failed to open an output stream.";
return;
@@ -71,8 +70,8 @@ class AudioStreamHandler::AudioStreamContainer
base::AutoLock al(state_lock_);
delayed_stop_posted_ = false;
- stop_closure_.Reset(base::Bind(
- &AudioStreamContainer::StopStream, base::Unretained(this)));
+ stop_closure_.Reset(base::Bind(&AudioStreamContainer::StopStream,
+ base::Unretained(this)));
if (started_) {
if (wav_audio_.AtEnd(cursor_))
@@ -81,9 +80,9 @@ class AudioStreamHandler::AudioStreamContainer
}
cursor_ = 0;
- started_ = true;
}
+ started_ = true;
if (g_audio_source_for_testing)
stream_->Start(g_audio_source_for_testing);
else
@@ -99,6 +98,7 @@ class AudioStreamHandler::AudioStreamContainer
if (stream_)
stream_->Close();
stream_ = NULL;
+ stop_closure_.Cancel();
}
private:
@@ -131,24 +131,25 @@ class AudioStreamHandler::AudioStreamContainer
void StopStream() {
DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread());
- base::AutoLock al(state_lock_);
-
if (stream_ && started_) {
+ // Do not hold the |state_lock_| while stopping the output stream.
stream_->Stop();
if (g_observer_for_testing)
g_observer_for_testing->OnStop(cursor_);
}
+
started_ = false;
}
+ // Must only be accessed on the AudioManager::GetTaskRunner() thread.
+ bool started_;
AudioOutputStream* stream_;
- const WavAudioHandler wav_audio_;
-
+ // All variables below must be accessed under |state_lock_| when |started_|.
base::Lock state_lock_;
size_t cursor_;
- bool started_;
bool delayed_stop_posted_;
+ const WavAudioHandler wav_audio_;
base::CancelableClosure stop_closure_;
DISALLOW_COPY_AND_ASSIGN(AudioStreamContainer);
« no previous file with comments | « base/debug/tsan_suppressions.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698