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

Unified Diff: third_party/WebKit/Source/platform/audio/HRTFDatabaseLoader.cpp

Issue 2154473003: Simplify locking in HRTFDatabaseLoader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « third_party/WebKit/Source/platform/audio/HRTFDatabaseLoader.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « third_party/WebKit/Source/platform/audio/HRTFDatabaseLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698