Index: media/audio/audio_device_thread.cc |
diff --git a/media/audio/audio_device_thread.cc b/media/audio/audio_device_thread.cc |
index 20874599e68f5f7cfddeff0022291e64aa718b6c..d0e6f293aebb80f6414d5ec582fddc167c0a8773 100644 |
--- a/media/audio/audio_device_thread.cc |
+++ b/media/audio/audio_device_thread.cc |
@@ -16,6 +16,7 @@ |
#include "base/memory/aligned_memory.h" |
#include "base/message_loop/message_loop.h" |
#include "base/numerics/safe_conversions.h" |
+#include "base/synchronization/lock.h" |
#include "base/threading/platform_thread.h" |
#include "base/threading/thread_restrictions.h" |
#include "media/base/audio_bus.h" |
@@ -45,6 +46,9 @@ class AudioDeviceThread::Thread |
// synchronously for the thread to terminate. |
void Stop(base::MessageLoop* loop_for_join); |
+ // Returns true if called on the device thread, otherwise false. |
+ bool BelongsToRenderingThread(); |
+ |
private: |
friend class base::RefCountedThreadSafe<AudioDeviceThread::Thread>; |
~Thread() override; |
@@ -63,6 +67,11 @@ class AudioDeviceThread::Thread |
const char* thread_name_; |
const bool synchronized_buffers_; |
+#if DCHECK_IS_ON() |
+ base::PlatformThreadRef device_thread_id_; |
+ base::Lock device_thread_id_lock_; |
+#endif |
+ |
DISALLOW_COPY_AND_ASSIGN(Thread); |
}; |
@@ -97,6 +106,11 @@ bool AudioDeviceThread::IsStopped() { |
return !thread_.get(); |
} |
+bool AudioDeviceThread::BelongsToRenderingThread() { |
DaleCurtis
2016/06/10 18:24:49
Instead of hopping through two locks, it seems lik
Henrik Grunell
2016/06/13 12:46:15
base::Thread corresponds to ADT::Thread. We can re
|
+ base::AutoLock auto_lock(thread_lock_); |
+ return thread_.get() ? thread_->BelongsToRenderingThread() : false; |
+} |
+ |
// AudioDeviceThread::Thread implementation |
AudioDeviceThread::Thread::Thread(AudioDeviceThread::Callback* callback, |
base::SyncSocket::Handle socket, |
@@ -145,7 +159,21 @@ void AudioDeviceThread::Thread::Stop(base::MessageLoop* loop_for_join) { |
} |
} |
+bool AudioDeviceThread::Thread::BelongsToRenderingThread() { |
+#if DCHECK_IS_ON() |
DaleCurtis
2016/06/10 18:24:49
Only ThreadCheckers disable for DCHECK, typically
Henrik Grunell
2016/06/13 12:46:15
OK, that's fine I think. Done.
|
+ base::AutoLock auto_lock(device_thread_id_lock_); |
+ return device_thread_id_ == PlatformThread::CurrentRef(); |
+#else |
+ return true; |
+#endif |
+} |
+ |
void AudioDeviceThread::Thread::ThreadMain() { |
+#if DCHECK_IS_ON() |
+ base::AutoLock auto_lock(device_thread_id_lock_); |
+ device_thread_id_ = PlatformThread::CurrentRef(); |
+#endif |
+ |
PlatformThread::SetName(thread_name_); |
// Singleton access is safe from this thread as long as callback is non-NULL. |