Ticket #989: 1.diff

File 1.diff, 1.3 KB (added by i.ponetaev.ndmsystems.com@…, 10 years ago)

patch for replacing clocksource for ngx_current_msec

  • src/core/ngx_times.c

    diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c
    index 843314a..2699499 100644
    a b ngx_time_update(void)  
    8383    ngx_uint_t       msec;
    8484    ngx_time_t      *tp;
    8585    struct timeval   tv;
     86    struct timespec  ts;
    8687
    8788    if (!ngx_trylock(&ngx_time_lock)) {
    8889        return;
    8990    }
    9091
     92    ngx_clock_gettime(&ts);
     93
     94    ngx_current_msec = (ngx_msec_t) ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
     95
    9196    ngx_gettimeofday(&tv);
    9297
    9398    sec = tv.tv_sec;
    9499    msec = tv.tv_usec / 1000;
    95100
    96     ngx_current_msec = (ngx_msec_t) sec * 1000 + msec;
    97 
    98101    tp = &cached_time[slot];
    99102
    100103    if (tp->sec == sec) {
  • src/os/unix/ngx_time.h

    diff --git a/src/os/unix/ngx_time.h b/src/os/unix/ngx_time.h
    index c128c9a..88fce84 100644
    a b void ngx_localtime(time_t s, ngx_tm_t *tm);  
    5858void ngx_libc_localtime(time_t s, struct tm *tm);
    5959void ngx_libc_gmtime(time_t s, struct tm *tm);
    6060
    61 #define ngx_gettimeofday(tp)  (void) gettimeofday(tp, NULL);
     61
     62#define ngx_clock_gettime(ts) (void) clock_gettime(CLOCK_MONOTONIC, ts)
     63#define ngx_gettimeofday(tp)  (void) gettimeofday(tp, NULL)
    6264#define ngx_msleep(ms)        (void) usleep(ms * 1000)
    6365#define ngx_sleep(s)          (void) sleep(s)
    6466