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

Side by Side Diff: Source/platform/audio/HRTFDatabaseLoader.cpp

Issue 1303153005: Introduce WebTaskRunner Patch 3/5 (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 3 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 unified diff | Download patch
OLDNEW
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
92 } 92 }
93 93
94 void HRTFDatabaseLoader::loadAsynchronously() 94 void HRTFDatabaseLoader::loadAsynchronously()
95 { 95 {
96 ASSERT(isMainThread()); 96 ASSERT(isMainThread());
97 97
98 MutexLocker locker(m_lock); 98 MutexLocker locker(m_lock);
99 if (!m_hrtfDatabase && !m_thread) { 99 if (!m_hrtfDatabase && !m_thread) {
100 // Start the asynchronous database loading process. 100 // Start the asynchronous database loading process.
101 m_thread = adoptPtr(Platform::current()->createThread("HRTF database loa der")); 101 m_thread = adoptPtr(Platform::current()->createThread("HRTF database loa der"));
102 m_thread->postTask(FROM_HERE, new Task(threadSafeBind(&HRTFDatabaseLoade r::loadTask, AllowCrossThreadAccess(this)))); 102 // TODO(alexclarke): Should this be posted as a loading task?
103 m_thread->defaultTaskRunner()->postTask(FROM_HERE, new Task(threadSafeBi nd(&HRTFDatabaseLoader::loadTask, AllowCrossThreadAccess(this))));
103 } 104 }
104 } 105 }
105 106
106 bool HRTFDatabaseLoader::isLoaded() 107 bool HRTFDatabaseLoader::isLoaded()
107 { 108 {
108 MutexLocker locker(m_lock); 109 MutexLocker locker(m_lock);
109 return m_hrtfDatabase; 110 return m_hrtfDatabase;
110 } 111 }
111 112
112 // This cleanup task is needed just to make sure that the loader thread finishes 113 // This cleanup task is needed just to make sure that the loader thread finishes
113 // the load task and thus the loader thread doesn't touch m_thread any more. 114 // the load task and thus the loader thread doesn't touch m_thread any more.
114 void HRTFDatabaseLoader::cleanupTask(TaskSynchronizer* sync) 115 void HRTFDatabaseLoader::cleanupTask(TaskSynchronizer* sync)
115 { 116 {
116 sync->taskCompleted(); 117 sync->taskCompleted();
117 } 118 }
118 119
119 void HRTFDatabaseLoader::waitForLoaderThreadCompletion() 120 void HRTFDatabaseLoader::waitForLoaderThreadCompletion()
120 { 121 {
121 if (!m_thread) 122 if (!m_thread)
122 return; 123 return;
123 124
124 TaskSynchronizer sync; 125 TaskSynchronizer sync;
125 m_thread->postTask(FROM_HERE, new Task(threadSafeBind(&HRTFDatabaseLoader::c leanupTask, AllowCrossThreadAccess(this), AllowCrossThreadAccess(&sync)))); 126 // TODO(alexclarke): Should this be posted as a loading task?
127 m_thread->defaultTaskRunner()->postTask(FROM_HERE, new Task(threadSafeBind(& HRTFDatabaseLoader::cleanupTask, AllowCrossThreadAccess(this), AllowCrossThreadA ccess(&sync))));
126 sync.waitForTaskCompletion(); 128 sync.waitForTaskCompletion();
127 m_thread.clear(); 129 m_thread.clear();
128 } 130 }
129 131
130 } // namespace blink 132 } // namespace blink
131 133
132 #endif // ENABLE(WEB_AUDIO) 134 #endif // ENABLE(WEB_AUDIO)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698