@ -55,10 +55,18 @@ struct LRUHandle {
// cache itself is counted as 1
// cache itself is counted as 1
// Include the following flags:
// Include the following flags:
// in_cache: whether this entry is referenced by the hash table.
// IN_CACHE: whether this entry is referenced by the hash table.
// is_high_pri: whether this entry is high priority entry.
// IS_HIGH_PRI: whether this entry is high priority entry.
// in_high_pri_pool: whether this entry is in high-pri pool.
// IN_HIGH_PRI_POOL: whether this entry is in high-pri pool.
char flags ;
// HAS_HIT: whether this entry has had any lookups (hits).
enum Flags : uint8_t {
IN_CACHE = ( 1 < < 0 ) ,
IS_HIGH_PRI = ( 1 < < 1 ) ,
IN_HIGH_PRI_POOL = ( 1 < < 2 ) ,
HAS_HIT = ( 1 < < 3 ) ,
} ;
uint8_t flags ;
uint32_t hash ; // Hash of key(); used for fast sharding and comparisons
uint32_t hash ; // Hash of key(); used for fast sharding and comparisons
@ -74,36 +82,36 @@ struct LRUHandle {
}
}
}
}
bool InCache ( ) { return flags & 1 ; }
bool InCache ( ) const { return flags & IN_CACHE ; }
bool IsHighPri ( ) { return flags & 2 ; }
bool IsHighPri ( ) const { return flags & IS_HIGH_PRI ; }
bool InHighPriPool ( ) { return flags & 4 ; }
bool InHighPriPool ( ) const { return flags & IN_HIGH_PRI_POOL ; }
bool HasHit ( ) { return flags & 8 ; }
bool HasHit ( ) const { return flags & HAS_HIT ; }
void SetInCache ( bool in_cache ) {
void SetInCache ( bool in_cache ) {
if ( in_cache ) {
if ( in_cache ) {
flags | = 1 ;
flags | = IN_CACHE ;
} else {
} else {
flags & = ~ 1 ;
flags & = ~ IN_CACHE ;
}
}
}
}
void SetPriority ( Cache : : Priority priority ) {
void SetPriority ( Cache : : Priority priority ) {
if ( priority = = Cache : : Priority : : HIGH ) {
if ( priority = = Cache : : Priority : : HIGH ) {
flags | = 2 ;
flags | = IS_HIGH_PRI ;
} else {
} else {
flags & = ~ 2 ;
flags & = ~ IS_HIGH_PRI ;
}
}
}
}
void SetInHighPriPool ( bool in_high_pri_pool ) {
void SetInHighPriPool ( bool in_high_pri_pool ) {
if ( in_high_pri_pool ) {
if ( in_high_pri_pool ) {
flags | = 4 ;
flags | = IN_HIGH_PRI_POOL ;
} else {
} else {
flags & = ~ 4 ;
flags & = ~ IN_HIGH_PRI_POOL ;
}
}
}
}
void SetHit ( ) { flags | = 8 ; }
void SetHit ( ) { flags | = HAS_HIT ; }
void Free ( ) {
void Free ( ) {
assert ( ( refs = = 1 & & InCache ( ) ) | | ( refs = = 0 & & ! InCache ( ) ) ) ;
assert ( ( refs = = 1 & & InCache ( ) ) | | ( refs = = 0 & & ! InCache ( ) ) ) ;