| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 // createAndLoadAsynchronouslyIfNecessary and because we haven't started | 92 // createAndLoadAsynchronouslyIfNecessary and because we haven't started |
| 93 // loadTask yet for this object. | 93 // loadTask yet for this object. |
| 94 DCHECK(!m_hrtfDatabase); | 94 DCHECK(!m_hrtfDatabase); |
| 95 DCHECK(!m_thread); | 95 DCHECK(!m_thread); |
| 96 | 96 |
| 97 // Start the asynchronous database loading process. | 97 // Start the asynchronous database loading process. |
| 98 m_thread = WTF::wrapUnique( | 98 m_thread = WTF::wrapUnique( |
| 99 Platform::current()->createThread("HRTF database loader")); | 99 Platform::current()->createThread("HRTF database loader")); |
| 100 // TODO(alexclarke): Should this be posted as a loading task? | 100 // TODO(alexclarke): Should this be posted as a loading task? |
| 101 m_thread->getWebTaskRunner()->postTask( | 101 m_thread->getWebTaskRunner()->postTask( |
| 102 BLINK_FROM_HERE, crossThreadBind(&HRTFDatabaseLoader::loadTask, | 102 BLINK_FROM_HERE, |
| 103 crossThreadUnretained(this))); | 103 crossThreadBind(&HRTFDatabaseLoader::loadTask, |
| 104 crossThreadUnretained(this))); |
| 104 } | 105 } |
| 105 | 106 |
| 106 HRTFDatabase* HRTFDatabaseLoader::database() { | 107 HRTFDatabase* HRTFDatabaseLoader::database() { |
| 107 DCHECK(!isMainThread()); | 108 DCHECK(!isMainThread()); |
| 108 | 109 |
| 109 // Seeing that this is only called from the audio thread, we can't block. | 110 // Seeing that this is only called from the audio thread, we can't block. |
| 110 // It's ok to return nullptr if we can't get the lock. | 111 // It's ok to return nullptr if we can't get the lock. |
| 111 MutexTryLocker tryLocker(m_lock); | 112 MutexTryLocker tryLocker(m_lock); |
| 112 | 113 |
| 113 if (!tryLocker.locked()) | 114 if (!tryLocker.locked()) |
| 114 return nullptr; | 115 return nullptr; |
| 115 | 116 |
| 116 return m_hrtfDatabase.get(); | 117 return m_hrtfDatabase.get(); |
| 117 } | 118 } |
| 118 | 119 |
| 119 // This cleanup task is needed just to make sure that the loader thread finishes | 120 // This cleanup task is needed just to make sure that the loader thread finishes |
| 120 // the load task and thus the loader thread doesn't touch m_thread any more. | 121 // the load task and thus the loader thread doesn't touch m_thread any more. |
| 121 void HRTFDatabaseLoader::cleanupTask(WaitableEvent* sync) { | 122 void HRTFDatabaseLoader::cleanupTask(WaitableEvent* sync) { |
| 122 sync->signal(); | 123 sync->signal(); |
| 123 } | 124 } |
| 124 | 125 |
| 125 void HRTFDatabaseLoader::waitForLoaderThreadCompletion() { | 126 void HRTFDatabaseLoader::waitForLoaderThreadCompletion() { |
| 126 if (!m_thread) | 127 if (!m_thread) |
| 127 return; | 128 return; |
| 128 | 129 |
| 129 WaitableEvent sync; | 130 WaitableEvent sync; |
| 130 // TODO(alexclarke): Should this be posted as a loading task? | 131 // TODO(alexclarke): Should this be posted as a loading task? |
| 131 m_thread->getWebTaskRunner()->postTask( | 132 m_thread->getWebTaskRunner()->postTask( |
| 132 BLINK_FROM_HERE, crossThreadBind(&HRTFDatabaseLoader::cleanupTask, | 133 BLINK_FROM_HERE, |
| 133 crossThreadUnretained(this), | 134 crossThreadBind(&HRTFDatabaseLoader::cleanupTask, |
| 134 crossThreadUnretained(&sync))); | 135 crossThreadUnretained(this), |
| 136 crossThreadUnretained(&sync))); |
| 135 sync.wait(); | 137 sync.wait(); |
| 136 m_thread.reset(); | 138 m_thread.reset(); |
| 137 } | 139 } |
| 138 | 140 |
| 139 } // namespace blink | 141 } // namespace blink |
| OLD | NEW |