Mercurial > hg > svcore
comparison data/fft/FFTDataServer.h @ 335:02d2ad95ea52 spectrogram-cache-rejig
* Get storage advice for each cache in an FFT data server. Allows us to be
more confident about the actual memory situation and cut over from memory
to disc part way through an FFT calculation if necessary. StorageAdviser
is now a bit too optimistic though (it's too keen to allocate large numbers
of small blocks in memory).
author | Chris Cannam |
---|---|
date | Tue, 13 Nov 2007 13:54:10 +0000 |
parents | aa8dbac62024 |
children | 115f60df1e4d |
comparison
equal
deleted
inserted
replaced
334:aa8dbac62024 | 335:02d2ad95ea52 |
---|---|
133 size_t m_width; | 133 size_t m_width; |
134 size_t m_height; | 134 size_t m_height; |
135 size_t m_cacheWidth; | 135 size_t m_cacheWidth; |
136 size_t m_cacheWidthPower; | 136 size_t m_cacheWidthPower; |
137 size_t m_cacheWidthMask; | 137 size_t m_cacheWidthMask; |
138 bool m_memoryCache; | 138 |
139 bool m_compactCache; | 139 int m_lastUsedCache; |
140 FFTCache *getCache(size_t x, size_t &col) { | |
141 col = x & m_cacheWidthMask; | |
142 int c = x >> m_cacheWidthPower; | |
143 // The only use of m_lastUsedCache without a lock is to | |
144 // establish whether a cache has been created at all (they're | |
145 // created on demand, but not destroyed until the server is). | |
146 if (c == m_lastUsedCache) return m_caches[c]; | |
147 else return getCacheAux(c); | |
148 } | |
149 bool haveCache(size_t x) { | |
150 int c = x >> m_cacheWidthPower; | |
151 if (c == m_lastUsedCache) return true; | |
152 else return (m_caches[c] != 0); | |
153 } | |
140 | 154 |
141 typedef std::vector<FFTCache *> CacheVector; | 155 typedef std::vector<FFTCache *> CacheVector; |
142 CacheVector m_caches; | 156 CacheVector m_caches; |
143 | 157 |
144 typedef std::deque<int> IntQueue; | 158 typedef std::deque<int> IntQueue; |
145 IntQueue m_dormantCaches; | 159 IntQueue m_dormantCaches; |
146 | 160 |
147 int m_lastUsedCache; | 161 StorageAdviser::Criteria m_criteria; |
148 FFTCache *getCache(size_t x, size_t &col) { | 162 |
149 col = x % m_cacheWidth; | 163 void getStorageAdvice(size_t w, size_t h, bool &memory, bool &compact); |
150 int c = x / m_cacheWidth; | |
151 // The only use of m_lastUsedCache without a lock is to | |
152 // establish whether a cache has been created at all (they're | |
153 // created on demand, but not destroyed until the server is). | |
154 if (c == m_lastUsedCache) return m_caches[c]; | |
155 else return getCacheAux(c); | |
156 } | |
157 bool haveCache(size_t x) { | |
158 int c = x / m_cacheWidth; | |
159 if (c == m_lastUsedCache) return true; | |
160 else return (m_caches[c] != 0); | |
161 } | |
162 | 164 |
163 FFTCache *getCacheAux(size_t c); | 165 FFTCache *getCacheAux(size_t c); |
164 QMutex m_writeMutex; | 166 QMutex m_writeMutex; |
165 QWaitCondition m_condition; | 167 QWaitCondition m_condition; |
166 | 168 |