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

Unified Diff: content/renderer/media/audio_device_thread.cc

Issue 9534002: Stop the AudioDeviceThread when the IO loop goes away. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove mutable. Stop thread synchronously if needed in ShutdownOnIOThread with IO exception. Created 8 years, 10 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 | « content/renderer/media/audio_device_thread.h ('k') | content/renderer/media/audio_input_device.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/audio_device_thread.cc
diff --git a/content/renderer/media/audio_device_thread.cc b/content/renderer/media/audio_device_thread.cc
index 4d06aa0fa95ff8f9e52645d9205520b13489a38c..c76f999d817ee207e36ea517e9435ea1390f5b39 100644
--- a/content/renderer/media/audio_device_thread.cc
+++ b/content/renderer/media/audio_device_thread.cc
@@ -7,7 +7,6 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop.h"
-#include "base/synchronization/lock.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread_restrictions.h"
#include "media/audio/audio_util.h"
@@ -27,6 +26,11 @@ class AudioDeviceThread::Thread
const char* thread_name);
void Start();
+
+ // Stops the thread. If |loop_for_join| is non-NULL, the function posts
+ // a task to join (close) the thread handle later instead of waiting for
+ // the thread. If loop_for_join is NULL, then the function waits
+ // synchronously for the thread to terminate.
void Stop(MessageLoop* loop_for_join);
private:
@@ -61,22 +65,25 @@ AudioDeviceThread::~AudioDeviceThread() {
void AudioDeviceThread::Start(AudioDeviceThread::Callback* callback,
base::SyncSocket::Handle socket,
const char* thread_name) {
+ base::AutoLock auto_lock(thread_lock_);
CHECK(thread_ == NULL);
thread_ = new AudioDeviceThread::Thread(callback, socket, thread_name);
thread_->Start();
}
void AudioDeviceThread::Stop(MessageLoop* loop_for_join) {
+ base::AutoLock auto_lock(thread_lock_);
if (thread_) {
- if (!loop_for_join) {
- loop_for_join = MessageLoop::current();
- CHECK(loop_for_join);
- }
thread_->Stop(loop_for_join);
thread_ = NULL;
}
}
+bool AudioDeviceThread::IsStopped() {
+ base::AutoLock auto_lock(thread_lock_);
+ return thread_ == NULL;
+}
+
// AudioDeviceThread::Thread implementation
AudioDeviceThread::Thread::Thread(AudioDeviceThread::Callback* callback,
base::SyncSocket::Handle socket,
@@ -113,8 +120,12 @@ void AudioDeviceThread::Thread::Stop(MessageLoop* loop_for_join) {
}
if (thread != base::kNullThreadHandle) {
- loop_for_join->PostTask(FROM_HERE,
- base::Bind(&base::PlatformThread::Join, thread));
+ if (loop_for_join) {
+ loop_for_join->PostTask(FROM_HERE,
+ base::Bind(&base::PlatformThread::Join, thread));
+ } else {
+ base::PlatformThread::Join(thread);
+ }
}
}
« no previous file with comments | « content/renderer/media/audio_device_thread.h ('k') | content/renderer/media/audio_input_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698