diff options
Diffstat (limited to 'src/evict.c')
-rw-r--r-- | src/evict.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/evict.c b/src/evict.c index 62753c5a7..bf5bea6b0 100644 --- a/src/evict.c +++ b/src/evict.c @@ -32,6 +32,7 @@ #include "server.h" #include "bio.h" +#include "atomicvar.h" /* ---------------------------------------------------------------------------- * Data structures @@ -72,6 +73,20 @@ unsigned int getLRUClock(void) { return (mstime()/LRU_CLOCK_RESOLUTION) & LRU_CLOCK_MAX; } +/* This function is used to obtain the current LRU clock. + * If the current resolution is lower than the frequency we refresh the + * LRU clock (as it should be in production servers) we return the + * precomputed value, otherwise we need to resort to a system call. */ +unsigned int LRU_CLOCK(void) { + unsigned int lruclock; + if (1000/server.hz <= LRU_CLOCK_RESOLUTION) { + atomicGet(server.lruclock,lruclock); + } else { + lruclock = getLRUClock(); + } + return lruclock; +} + /* Given an object returns the min number of milliseconds the object was never * requested, using an approximated LRU algorithm. */ unsigned long long estimateObjectIdleTime(robj *o) { |