MCPcopy Create free account
hub / github.com/ImageEngine/cortex / testLRUCacheThreading

Function testLRUCacheThreading

src/IECorePython/LRUCacheBinding.cpp:202–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200};
201
202void testLRUCacheThreading( int numIterations, int numValues, int maxCost, int clearFrequency = 0 )
203{
204 // do lots of parallel cache accesses. then clear the cache in the main
205 // thread and check that it has emptied successfully, to ensure that the
206 // cost counting has been accurate.
207
208 TestCache cache( get, maxCost );
209 tbb::task_group_context taskGroupContext( tbb::task_group_context::isolated );
210 parallel_for( blocked_range<size_t>( 0, numIterations ), GetFromTestCache( cache, numValues, clearFrequency ), taskGroupContext);
211
212 if( cache.currentCost() > cache.getMaxCost() )
213 {
214 throw Exception( "LRUCache exceeds maximum cost" );
215 }
216
217 cache.clear();
218 if( cache.currentCost() != 0 )
219 {
220 throw Exception( "Cost not 0 after LRUCache::clear()" );
221 }
222
223 // as above, but using setMaxCost( 0 ) to clear the cache.
224
225 TestCache cache2( get, maxCost );
226 parallel_for( blocked_range<size_t>( 0, numIterations ), GetFromTestCache( cache2, numValues, clearFrequency ), taskGroupContext );
227
228 if( cache2.currentCost() > cache2.getMaxCost() )
229 {
230 throw Exception( "LRUCache exceeds maximum cost" );
231 }
232
233 cache2.setMaxCost( 0 );
234 if( cache2.currentCost() != 0 )
235 {
236 throw Exception( "Cost not 0 after LRUCache::setMaxCost( 0 )" );
237 }
238}
239
240typedef LRUCache<int, int, LRUCachePolicy::Serial> SerialTestCache;
241typedef LRUCache<int, int, LRUCachePolicy::Parallel> ParallelTestCache;

Callers

nothing calls this directly

Calls 2

GetFromTestCacheClass · 0.85
clearMethod · 0.45

Tested by

no test coverage detected