| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 HRTFDatabaseLoader::HRTFDatabaseLoader(float sampleRate) | 65 HRTFDatabaseLoader::HRTFDatabaseLoader(float sampleRate) |
| 66 : m_databaseSampleRate(sampleRate) | 66 : m_databaseSampleRate(sampleRate) |
| 67 { | 67 { |
| 68 ASSERT(isMainThread()); | 68 ASSERT(isMainThread()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 HRTFDatabaseLoader::~HRTFDatabaseLoader() | 71 HRTFDatabaseLoader::~HRTFDatabaseLoader() |
| 72 { | 72 { |
| 73 ASSERT(isMainThread()); | 73 ASSERT(isMainThread()); |
| 74 | 74 |
| 75 MutexLocker locker(m_lock); |
| 75 waitForLoaderThreadCompletion(); | 76 waitForLoaderThreadCompletion(); |
| 76 m_hrtfDatabase.clear(); | 77 m_hrtfDatabase.clear(); |
| 77 } | 78 } |
| 78 | 79 |
| 79 void HRTFDatabaseLoader::load() | 80 void HRTFDatabaseLoader::load() |
| 80 { | 81 { |
| 81 ASSERT(!isMainThread()); | 82 ASSERT(!isMainThread()); |
| 83 MutexLocker locker(m_lock); |
| 82 if (!m_hrtfDatabase) { | 84 if (!m_hrtfDatabase) { |
| 83 // Load the default HRTF database. | 85 // Load the default HRTF database. |
| 84 m_hrtfDatabase = HRTFDatabase::create(m_databaseSampleRate); | 86 m_hrtfDatabase = HRTFDatabase::create(m_databaseSampleRate); |
| 85 } | 87 } |
| 86 } | 88 } |
| 87 | 89 |
| 88 void HRTFDatabaseLoader::loadAsynchronously() | 90 void HRTFDatabaseLoader::loadAsynchronously() |
| 89 { | 91 { |
| 90 ASSERT(isMainThread()); | 92 ASSERT(isMainThread()); |
| 91 | 93 |
| 92 MutexLocker locker(m_threadLock); | 94 MutexLocker locker(m_lock); |
| 93 | |
| 94 if (!m_hrtfDatabase && !m_databaseLoaderThread) { | 95 if (!m_hrtfDatabase && !m_databaseLoaderThread) { |
| 95 // Start the asynchronous database loading process. | 96 // Start the asynchronous database loading process. |
| 96 m_databaseLoaderThread = adoptPtr(Platform::current()->createThread("HRT
F database loader")); | 97 m_databaseLoaderThread = adoptPtr(Platform::current()->createThread("HRT
F database loader")); |
| 97 m_databaseLoaderThread->postTask(new Task(WTF::bind(&HRTFDatabaseLoader:
:load, this))); | 98 m_databaseLoaderThread->postTask(new Task(WTF::bind(&HRTFDatabaseLoader:
:load, this))); |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 | 101 |
| 101 bool HRTFDatabaseLoader::isLoaded() const | 102 bool HRTFDatabaseLoader::isLoaded() |
| 102 { | 103 { |
| 104 MutexLocker locker(m_lock); |
| 103 return m_hrtfDatabase; | 105 return m_hrtfDatabase; |
| 104 } | 106 } |
| 105 | 107 |
| 106 void HRTFDatabaseLoader::waitForLoaderThreadCompletion() | 108 void HRTFDatabaseLoader::waitForLoaderThreadCompletion() |
| 107 { | 109 { |
| 108 MutexLocker locker(m_threadLock); | |
| 109 m_databaseLoaderThread.clear(); | 110 m_databaseLoaderThread.clear(); |
| 110 } | 111 } |
| 111 | 112 |
| 112 } // namespace blink | 113 } // namespace blink |
| 113 | 114 |
| 114 #endif // ENABLE(WEB_AUDIO) | 115 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |