Chromium Code Reviews| Index: third_party/WebKit/Source/platform/audio/HRTFDatabaseLoader.cpp |
| diff --git a/third_party/WebKit/Source/platform/audio/HRTFDatabaseLoader.cpp b/third_party/WebKit/Source/platform/audio/HRTFDatabaseLoader.cpp |
| index 223293a7ed3a8adaab4ace0899f7ef82ce3db39c..601ae5119be969b5a49bfee9ab170dbf3d8db5ec 100644 |
| --- a/third_party/WebKit/Source/platform/audio/HRTFDatabaseLoader.cpp |
| +++ b/third_party/WebKit/Source/platform/audio/HRTFDatabaseLoader.cpp |
| @@ -78,31 +78,37 @@ void HRTFDatabaseLoader::loadTask() |
| { |
| ASSERT(!isMainThread()); |
|
hongchan
2016/07/15 16:19:00
I don't mind changing this to DCHECK.
|
| - { |
| - MutexLocker locker(m_lock); |
| - if (!m_hrtfDatabase) { |
| - // Load the default HRTF database. |
| - m_hrtfDatabase = HRTFDatabase::create(m_databaseSampleRate); |
| - } |
| - } |
| + DCHECK(!m_hrtfDatabase); |
| + |
| + MutexLocker locker(m_lock); |
| + // Load the default HRTF database. |
| + m_hrtfDatabase = HRTFDatabase::create(m_databaseSampleRate); |
| } |
| void HRTFDatabaseLoader::loadAsynchronously() |
| { |
| ASSERT(isMainThread()); |
| - MutexLocker locker(m_lock); |
| - if (!m_hrtfDatabase && !m_thread) { |
| - // Start the asynchronous database loading process. |
| - m_thread = wrapUnique(Platform::current()->createThread("HRTF database loader")); |
| - // TODO(alexclarke): Should this be posted as a loading task? |
| - m_thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, crossThreadBind(&HRTFDatabaseLoader::loadTask, crossThreadUnretained(this))); |
| - } |
| + DCHECK(!m_hrtfDatabase); |
| + DCHECK(!m_thread); |
| + |
| + // Start the asynchronous database loading process. |
| + m_thread = wrapUnique(Platform::current()->createThread("HRTF database loader")); |
|
hongchan
2016/07/15 16:19:00
Is wrapUnique necessary here?
Raymond Toy
2016/07/15 16:27:07
Don't know. I didn't change this.
|
| + // TODO(alexclarke): Should this be posted as a loading task? |
| + m_thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, crossThreadBind(&HRTFDatabaseLoader::loadTask, crossThreadUnretained(this))); |
| } |
| -bool HRTFDatabaseLoader::isLoaded() |
| +HRTFDatabase* HRTFDatabaseLoader::database() |
| { |
| - MutexLocker locker(m_lock); |
| + DCHECK(!isMainThread()); |
| + |
| + // Seeing that this is only called from the audio thread, we can't block. |
| + // It's ok to return false if we can't get the lock. |
| + MutexTryLocker tryLocker(m_lock); |
|
hongchan
2016/07/15 16:19:00
How is this tryLocker is connected to the audio th
Raymond Toy
2016/07/15 16:27:07
Yeah, this is for protecting access to m_hrtfDatab
|
| + |
| + if (tryLocker.locked()) |
| + return nullptr; |
| + |
| return m_hrtfDatabase.get(); |
| } |