@ -164,6 +164,9 @@ class LRUCache {
return usage_ ;
}
void ApplyToAllCacheEntries ( void ( * callback ) ( void * , size_t ) ,
bool thread_safe ) ;
private :
void LRU_Remove ( LRUHandle * e ) ;
void LRU_Append ( LRUHandle * e ) ;
@ -220,6 +223,19 @@ void LRUCache::FreeEntry(LRUHandle* e) {
free ( e ) ;
}
void LRUCache : : ApplyToAllCacheEntries ( void ( * callback ) ( void * , size_t ) ,
bool thread_safe ) {
if ( thread_safe ) {
mutex_ . Lock ( ) ;
}
for ( auto e = lru_ . next ; e ! = & lru_ ; e = e - > next ) {
callback ( e - > value , e - > charge ) ;
}
if ( thread_safe ) {
mutex_ . Unlock ( ) ;
}
}
void LRUCache : : LRU_Remove ( LRUHandle * e ) {
e - > next - > prev = e - > prev ;
e - > prev - > next = e - > next ;
@ -432,6 +448,14 @@ class ShardedLRUCache : public Cache {
virtual void DisownData ( ) {
shards_ = nullptr ;
}
virtual void ApplyToAllCacheEntries ( void ( * callback ) ( void * , size_t ) ,
bool thread_safe ) override {
int num_shards = 1 < < num_shard_bits_ ;
for ( int s = 0 ; s < num_shards ; s + + ) {
shards_ [ s ] . ApplyToAllCacheEntries ( callback , thread_safe ) ;
}
}
} ;
} // end anonymous namespace