memcached.c
static void clock_handler(const int fd, const short which, void *arg) {
    struct timeval t = {.tv_sec = 1, .tv_usec = 0};
    static bool initialized = false;
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
    static bool monotonic = false;
    static time_t monotonic_start;
#endif

    if (initialized) {
        /* only delete the event if it's actually there. */
        evtimer_del(&clockevent);
    } else {
        initialized = true;
        /* process_started is initialized to time() - 2. We initialize to 1 so
         * flush_all won't underflow during tests. */
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
        struct timespec ts;
        if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
            monotonic = true;
            monotonic_start = ts.tv_sec - 2;
        }
#endif
    }

    evtimer_set(&clockevent, clock_handler, 0);
    event_base_set(main_base, &clockevent);
    evtimer_add(&clockevent, &t);

#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
    if (monotonic) {
        struct timespec ts;
        if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
            return;
        current_time = (rel_time_t) (ts.tv_sec - monotonic_start);
        return;
    }
#endif
    {
        struct timeval tv;
        gettimeofday(&tv, NULL);
        current_time = (rel_time_t) (tv.tv_sec - process_started);
    }
}
/* libevent uses a monotonic clock when available for event scheduling. Aside
 * from jitter, simply ticking our internal timer here is accurate enough.
 * Note that users who are setting explicit dates for expiration times *must*
 * ensure their clocks are correct before starting memcached. */
libevent uses a monotonic clock when available for event scheduling. Aside
from jitter, simply ticking our internal timer here is accurate enough.
Note that users who are setting explicit dates for expiration times *must
ensure their clocks are correct before starting memcached.
libevent uses a monotonic clock when available for event scheduling . Aside from jitter simply ticking our internal timer here is accurate enough . Note that users who are setting explicit dates for expiration times * must ensure their clocks are correct before starting memcached .
static void clock_handler(const int fd, const short which, void *arg) {
    struct timeval t = {.tv_sec = 1, .tv_usec = 0};
    static bool initialized = false;
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
    static bool monotonic = false;
    static time_t monotonic_start;
#endif
    if (initialized) {
        evtimer_del(&clockevent);
    } else {
        initialized = true;
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
        struct timespec ts;
        if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
            monotonic = true;
            monotonic_start = ts.tv_sec - 2;
        }
#endif
    }
    evtimer_set(&clockevent, clock_handler, 0);
    event_base_set(main_base, &clockevent);
    evtimer_add(&clockevent, &t);
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
    if (monotonic) {
        struct timespec ts;
        if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
            return;
        current_time = (rel_time_t) (ts.tv_sec - monotonic_start);
        return;
    }
#endif
    {
        struct timeval tv;
        gettimeofday(&tv, NULL);
        current_time = (rel_time_t) (tv.tv_sec - process_started);
    }
}
static void clock_handler ( const int fd , const short which , void * arg ) { struct timeval t = { . tv_sec = 1 , . tv_usec = 0 } ; static bool initialized = false ; #if defined ( HAVE_CLOCK_GETTIME ) && defined ( CLOCK_MONOTONIC ) static bool monotonic = false ; static time_t monotonic_start ; #endif if ( initialized ) { evtimer_del ( & clockevent ) ; } else { initialized = true ; #if defined ( HAVE_CLOCK_GETTIME ) && defined ( CLOCK_MONOTONIC ) struct timespec ts ; if ( clock_gettime ( CLOCK_MONOTONIC , & ts ) == 0 ) { monotonic = true ; monotonic_start = ts . tv_sec - 2 ; } #endif } evtimer_set ( & clockevent , clock_handler , 0 ) ; event_base_set ( main_base , & clockevent ) ; evtimer_add ( & clockevent , & t ) ; #if defined ( HAVE_CLOCK_GETTIME ) && defined ( CLOCK_MONOTONIC ) if ( monotonic ) { struct timespec ts ; if ( clock_gettime ( CLOCK_MONOTONIC , & ts ) == -1 ) return ; current_time = ( rel_time_t ) ( ts . tv_sec - monotonic_start ) ; return ; } #endif { struct timeval tv ; gettimeofday ( & tv , NULL ) ; current_time = ( rel_time_t ) ( tv . tv_sec - process_started ) ; } }
libevent uses a monotonic clock when available for event scheduling.
libevent uses a monotonic clock when available for event scheduling .
/* only delete the event if it's actually there. */ /* process_started is initialized to time() - 2. We initialize to 1 so
         * flush_all won't underflow during tests. */