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

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

Issue 666213003: HRTFDatabaseLoader needs to acquire a lock when accessing m_hrtfDatabase (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « Source/platform/audio/HRTFDatabaseLoader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)
OLDNEW
« no previous file with comments | « Source/platform/audio/HRTFDatabaseLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698