Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 | 69 |
| 70 HRTFDatabaseLoader::~HRTFDatabaseLoader() | 70 HRTFDatabaseLoader::~HRTFDatabaseLoader() |
| 71 { | 71 { |
| 72 ASSERT(isMainThread()); | 72 ASSERT(isMainThread()); |
| 73 ASSERT(!m_thread); | 73 ASSERT(!m_thread); |
| 74 loaderMap().remove(m_databaseSampleRate); | 74 loaderMap().remove(m_databaseSampleRate); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void HRTFDatabaseLoader::loadTask() | 77 void HRTFDatabaseLoader::loadTask() |
| 78 { | 78 { |
| 79 ASSERT(!isMainThread()); | 79 ASSERT(!isMainThread()); |
|
hongchan
2016/07/15 16:19:00
I don't mind changing this to DCHECK.
| |
| 80 | 80 |
| 81 { | 81 DCHECK(!m_hrtfDatabase); |
| 82 MutexLocker locker(m_lock); | 82 |
| 83 if (!m_hrtfDatabase) { | 83 MutexLocker locker(m_lock); |
| 84 // Load the default HRTF database. | 84 // Load the default HRTF database. |
| 85 m_hrtfDatabase = HRTFDatabase::create(m_databaseSampleRate); | 85 m_hrtfDatabase = HRTFDatabase::create(m_databaseSampleRate); |
| 86 } | |
| 87 } | |
| 88 } | 86 } |
| 89 | 87 |
| 90 void HRTFDatabaseLoader::loadAsynchronously() | 88 void HRTFDatabaseLoader::loadAsynchronously() |
| 91 { | 89 { |
| 92 ASSERT(isMainThread()); | 90 ASSERT(isMainThread()); |
| 93 | 91 |
| 94 MutexLocker locker(m_lock); | 92 DCHECK(!m_hrtfDatabase); |
| 95 if (!m_hrtfDatabase && !m_thread) { | 93 DCHECK(!m_thread); |
| 96 // Start the asynchronous database loading process. | 94 |
| 97 m_thread = wrapUnique(Platform::current()->createThread("HRTF database l oader")); | 95 // Start the asynchronous database loading process. |
| 98 // TODO(alexclarke): Should this be posted as a loading task? | 96 m_thread = wrapUnique(Platform::current()->createThread("HRTF database loade r")); |
|
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.
| |
| 99 m_thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, crossThreadBind( &HRTFDatabaseLoader::loadTask, crossThreadUnretained(this))); | 97 // TODO(alexclarke): Should this be posted as a loading task? |
| 100 } | 98 m_thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, crossThreadBind(&HRT FDatabaseLoader::loadTask, crossThreadUnretained(this))); |
| 101 } | 99 } |
| 102 | 100 |
| 103 bool HRTFDatabaseLoader::isLoaded() | 101 HRTFDatabase* HRTFDatabaseLoader::database() |
| 104 { | 102 { |
| 105 MutexLocker locker(m_lock); | 103 DCHECK(!isMainThread()); |
| 104 | |
| 105 // Seeing that this is only called from the audio thread, we can't block. | |
| 106 // It's ok to return false if we can't get the lock. | |
| 107 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
| |
| 108 | |
| 109 if (tryLocker.locked()) | |
| 110 return nullptr; | |
| 111 | |
| 106 return m_hrtfDatabase.get(); | 112 return m_hrtfDatabase.get(); |
| 107 } | 113 } |
| 108 | 114 |
| 109 // This cleanup task is needed just to make sure that the loader thread finishes | 115 // This cleanup task is needed just to make sure that the loader thread finishes |
| 110 // the load task and thus the loader thread doesn't touch m_thread any more. | 116 // the load task and thus the loader thread doesn't touch m_thread any more. |
| 111 void HRTFDatabaseLoader::cleanupTask(TaskSynchronizer* sync) | 117 void HRTFDatabaseLoader::cleanupTask(TaskSynchronizer* sync) |
| 112 { | 118 { |
| 113 sync->taskCompleted(); | 119 sync->taskCompleted(); |
| 114 } | 120 } |
| 115 | 121 |
| 116 void HRTFDatabaseLoader::waitForLoaderThreadCompletion() | 122 void HRTFDatabaseLoader::waitForLoaderThreadCompletion() |
| 117 { | 123 { |
| 118 if (!m_thread) | 124 if (!m_thread) |
| 119 return; | 125 return; |
| 120 | 126 |
| 121 TaskSynchronizer sync; | 127 TaskSynchronizer sync; |
| 122 // TODO(alexclarke): Should this be posted as a loading task? | 128 // TODO(alexclarke): Should this be posted as a loading task? |
| 123 m_thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, crossThreadBind(&HRT FDatabaseLoader::cleanupTask, crossThreadUnretained(this), crossThreadUnretained (&sync))); | 129 m_thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, crossThreadBind(&HRT FDatabaseLoader::cleanupTask, crossThreadUnretained(this), crossThreadUnretained (&sync))); |
| 124 sync.waitForTaskCompletion(); | 130 sync.waitForTaskCompletion(); |
| 125 m_thread.reset(); | 131 m_thread.reset(); |
| 126 } | 132 } |
| 127 | 133 |
| 128 } // namespace blink | 134 } // namespace blink |
| OLD | NEW |