diff options
author | Igor Sysoev <igor@sysoev.ru> | 2010-03-13 21:08:07 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2010-03-13 21:08:07 +0300 |
commit | 2f916a972139be74d437e40bdc7d236401123170 (patch) | |
tree | fcd2498751fa4da54ce7b32cfea08975893d83c9 /src | |
parent | b80f68aeda3d958c6c8e52a796fcc561cd9c6e1a (diff) |
*) use previously cached GMT offset value to update time from a signal handler
*) change ngx_time_update() interface since there are no notification methods
those return time
Diffstat (limited to 'src')
-rw-r--r-- | src/core/ngx_cycle.c | 2 | ||||
-rw-r--r-- | src/core/ngx_times.c | 43 | ||||
-rw-r--r-- | src/core/ngx_times.h | 2 | ||||
-rw-r--r-- | src/event/modules/ngx_devpoll_module.c | 2 | ||||
-rw-r--r-- | src/event/modules/ngx_epoll_module.c | 2 | ||||
-rw-r--r-- | src/event/modules/ngx_eventport_module.c | 4 | ||||
-rw-r--r-- | src/event/modules/ngx_iocp_module.c | 4 | ||||
-rw-r--r-- | src/event/modules/ngx_kqueue_module.c | 4 | ||||
-rw-r--r-- | src/event/modules/ngx_poll_module.c | 2 | ||||
-rw-r--r-- | src/event/modules/ngx_rtsig_module.c | 8 | ||||
-rw-r--r-- | src/event/modules/ngx_select_module.c | 2 | ||||
-rw-r--r-- | src/event/modules/ngx_win32_select_module.c | 2 | ||||
-rw-r--r-- | src/http/ngx_http_file_cache.c | 4 | ||||
-rw-r--r-- | src/os/unix/ngx_process.c | 2 | ||||
-rw-r--r-- | src/os/unix/ngx_process_cycle.c | 6 | ||||
-rw-r--r-- | src/os/win32/ngx_process.c | 2 | ||||
-rw-r--r-- | src/os/win32/ngx_process_cycle.c | 14 |
17 files changed, 62 insertions, 43 deletions
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c index d77dcc13d..2c3dcc848 100644 --- a/src/core/ngx_cycle.c +++ b/src/core/ngx_cycle.c @@ -63,7 +63,7 @@ ngx_init_cycle(ngx_cycle_t *old_cycle) tp = ngx_timeofday(); tp->sec = 0; - ngx_time_update(0, 0); + ngx_time_update(0); log = old_cycle->log; diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c index 3105beb47..94993e291 100644 --- a/src/core/ngx_times.c +++ b/src/core/ngx_times.c @@ -28,6 +28,17 @@ volatile ngx_str_t ngx_cached_err_log_time; volatile ngx_str_t ngx_cached_http_time; volatile ngx_str_t ngx_cached_http_log_time; +#if !(NGX_HAVE_GETTIMEZONE) + +/* + * locatime() and localtime_r() are not Async-Signal-Safe functions, therefore, + * if ngx_time_update() is called by signal handler, it uses the cached + * GMT offset value. Fortunately the value is changed only two times a year. + */ + +static ngx_int_t cached_gmtoff; +#endif + static ngx_time_t cached_time[NGX_TIME_SLOTS]; static u_char cached_err_log_time[NGX_TIME_SLOTS] [sizeof("1970/09/28 12:00:00")]; @@ -50,15 +61,17 @@ ngx_time_init(void) ngx_cached_time = &cached_time[0]; - ngx_time_update(0, 0); + ngx_time_update(0); } void -ngx_time_update(time_t sec, ngx_uint_t msec) +ngx_time_update(ngx_uint_t use_cached_gmtoff) { u_char *p0, *p1, *p2; ngx_tm_t tm, gmt; + time_t sec; + ngx_uint_t msec; ngx_time_t *tp; struct timeval tv; @@ -66,12 +79,10 @@ ngx_time_update(time_t sec, ngx_uint_t msec) return; } - if (sec == 0) { - ngx_gettimeofday(&tv); + ngx_gettimeofday(&tv); - sec = tv.tv_sec; - msec = tv.tv_usec / 1000; - } + sec = tv.tv_sec; + msec = tv.tv_usec / 1000; ngx_current_msec = (ngx_msec_t) sec * 1000 + msec; @@ -109,15 +120,23 @@ ngx_time_update(time_t sec, ngx_uint_t msec) tp->gmtoff = ngx_gettimezone(); ngx_gmtime(sec + tp->gmtoff * 60, &tm); -#elif (NGX_HAVE_GMTOFF) +#else + + if (use_cached_gmtoff) { + ngx_gmtime(sec + cached_gmtoff * 60, &tm); - ngx_localtime(sec, &tm); - tp->gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60); + } else { + ngx_localtime(sec, &tm); +#if (NGX_HAVE_GMTOFF) + cached_gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60); #else + cached_gmtoff = ngx_timezone(tm.ngx_tm_isdst); +#endif + + } - ngx_localtime(sec, &tm); - tp->gmtoff = ngx_timezone(tm.ngx_tm_isdst); + tp->gmtoff = cached_gmtoff; #endif diff --git a/src/core/ngx_times.h b/src/core/ngx_times.h index 8363ca136..4259d17d1 100644 --- a/src/core/ngx_times.h +++ b/src/core/ngx_times.h @@ -20,7 +20,7 @@ typedef struct { void ngx_time_init(void); -void ngx_time_update(time_t sec, ngx_uint_t msec); +void ngx_time_update(ngx_uint_t use_cached_gmtoff); u_char *ngx_http_time(u_char *buf, time_t t); u_char *ngx_http_cookie_time(u_char *buf, time_t t); void ngx_gmtime(time_t t, ngx_tm_t *tp); diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c index f133b7249..3655eb98e 100644 --- a/src/event/modules/ngx_devpoll_module.c +++ b/src/event/modules/ngx_devpoll_module.c @@ -372,7 +372,7 @@ ngx_devpoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, err = (events == -1) ? ngx_errno : 0; if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) { - ngx_time_update(0, 0); + ngx_time_update(0); } if (err) { diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c index 3c1ca2ac2..838573aef 100644 --- a/src/event/modules/ngx_epoll_module.c +++ b/src/event/modules/ngx_epoll_module.c @@ -532,7 +532,7 @@ ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags) err = (events == -1) ? ngx_errno : 0; if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) { - ngx_time_update(0, 0); + ngx_time_update(0); } if (err) { diff --git a/src/event/modules/ngx_eventport_module.c b/src/event/modules/ngx_eventport_module.c index 842d631af..8abf4d38c 100644 --- a/src/event/modules/ngx_eventport_module.c +++ b/src/event/modules/ngx_eventport_module.c @@ -405,7 +405,7 @@ ngx_eventport_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, err = ngx_errno; if (flags & NGX_UPDATE_TIME) { - ngx_time_update(0, 0); + ngx_time_update(0); } if (n == -1) { @@ -439,7 +439,7 @@ ngx_eventport_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, for (i = 0; i < events; i++) { if (event_list[i].portev_source == PORT_SOURCE_TIMER) { - ngx_time_update(0, 0); + ngx_time_update(0); continue; } diff --git a/src/event/modules/ngx_iocp_module.c b/src/event/modules/ngx_iocp_module.c index 837517151..5ce867442 100644 --- a/src/event/modules/ngx_iocp_module.c +++ b/src/event/modules/ngx_iocp_module.c @@ -163,7 +163,7 @@ ngx_iocp_timer(void *data) for ( ;; ) { Sleep(timer); - ngx_time_update(0, 0); + ngx_time_update(0); #if 1 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0, "timer"); #endif @@ -258,7 +258,7 @@ ngx_int_t ngx_iocp_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, delta = ngx_current_msec; if (flags & NGX_UPDATE_TIME) { - ngx_time_update(0, 0); + ngx_time_update(0); } ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0, diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c index b6dfa8fa1..e295d834b 100644 --- a/src/event/modules/ngx_kqueue_module.c +++ b/src/event/modules/ngx_kqueue_module.c @@ -538,7 +538,7 @@ ngx_kqueue_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, err = (events == -1) ? ngx_errno : 0; if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) { - ngx_time_update(0, 0); + ngx_time_update(0); } ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, @@ -589,7 +589,7 @@ ngx_kqueue_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, #if (NGX_HAVE_TIMER_EVENT) if (event_list[i].filter == EVFILT_TIMER) { - ngx_time_update(0, 0); + ngx_time_update(0); continue; } diff --git a/src/event/modules/ngx_poll_module.c b/src/event/modules/ngx_poll_module.c index 3b98c19fe..dc11d2ee2 100644 --- a/src/event/modules/ngx_poll_module.c +++ b/src/event/modules/ngx_poll_module.c @@ -263,7 +263,7 @@ ngx_poll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags) err = (ready == -1) ? ngx_errno : 0; if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) { - ngx_time_update(0, 0); + ngx_time_update(0); } ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, diff --git a/src/event/modules/ngx_rtsig_module.c b/src/event/modules/ngx_rtsig_module.c index 926be0de3..a8cf4ab57 100644 --- a/src/event/modules/ngx_rtsig_module.c +++ b/src/event/modules/ngx_rtsig_module.c @@ -323,7 +323,7 @@ ngx_rtsig_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags) "rtsig signo:%d", signo); if (flags & NGX_UPDATE_TIME) { - ngx_time_update(0, 0); + ngx_time_update(0); } if (err == NGX_EAGAIN) { @@ -349,7 +349,7 @@ ngx_rtsig_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags) signo, si.si_fd, si.si_band); if (flags & NGX_UPDATE_TIME) { - ngx_time_update(0, 0); + ngx_time_update(0); } rtscf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_rtsig_module); @@ -419,7 +419,7 @@ ngx_rtsig_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags) } else if (signo == SIGALRM) { - ngx_time_update(0, 0); + ngx_time_update(0); return NGX_OK; @@ -671,7 +671,7 @@ ngx_rtsig_process_overflow(ngx_cycle_t *cycle, ngx_msec_t timer, } if (flags & NGX_UPDATE_TIME) { - ngx_time_update(0, 0); + ngx_time_update(0); } ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, diff --git a/src/event/modules/ngx_select_module.c b/src/event/modules/ngx_select_module.c index 9f5b43b71..0ca5facec 100644 --- a/src/event/modules/ngx_select_module.c +++ b/src/event/modules/ngx_select_module.c @@ -263,7 +263,7 @@ ngx_select_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, err = (ready == -1) ? ngx_errno : 0; if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) { - ngx_time_update(0, 0); + ngx_time_update(0); } ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, diff --git a/src/event/modules/ngx_win32_select_module.c b/src/event/modules/ngx_win32_select_module.c index 8c22f397a..8a3264df6 100644 --- a/src/event/modules/ngx_win32_select_module.c +++ b/src/event/modules/ngx_win32_select_module.c @@ -269,7 +269,7 @@ ngx_select_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, err = (ready == -1) ? ngx_socket_errno : 0; if (flags & NGX_UPDATE_TIME) { - ngx_time_update(0, 0); + ngx_time_update(0); } ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c index bd315eaa2..d24966fad 100644 --- a/src/http/ngx_http_file_cache.c +++ b/src/http/ngx_http_file_cache.c @@ -1216,7 +1216,7 @@ ngx_http_file_cache_manager_sleep(ngx_http_file_cache_t *cache) if (cache->files++ > 100) { - ngx_time_update(0, 0); + ngx_time_update(0); elapsed = ngx_abs((ngx_msec_int_t) (ngx_current_msec - cache->last)); @@ -1233,7 +1233,7 @@ ngx_http_file_cache_manager_sleep(ngx_http_file_cache_t *cache) ngx_msleep(200); - ngx_time_update(0, 0); + ngx_time_update(0); } cache->last = ngx_current_msec; diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c index 0d08349ee..4c418000a 100644 --- a/src/os/unix/ngx_process.c +++ b/src/os/unix/ngx_process.c @@ -317,7 +317,7 @@ ngx_signal_handler(int signo) } } - ngx_time_update(0, 0); + ngx_time_update(1); action = ""; diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c index 06e020e06..18046384a 100644 --- a/src/os/unix/ngx_process_cycle.c +++ b/src/os/unix/ngx_process_cycle.c @@ -168,7 +168,7 @@ ngx_master_process_cycle(ngx_cycle_t *cycle) sigsuspend(&set); - ngx_time_update(0, 0); + ngx_time_update(0); ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "wake up, sigio %i", sigio); @@ -1342,7 +1342,7 @@ ngx_cache_manager_process_handler(ngx_event_t *ev) next = (n <= next) ? n : next; - ngx_time_update(0, 0); + ngx_time_update(0); } } @@ -1372,7 +1372,7 @@ ngx_cache_loader_process_handler(ngx_event_t *ev) if (path[i]->loader) { path[i]->loader(path[i]->data); - ngx_time_update(0, 0); + ngx_time_update(0); } } diff --git a/src/os/win32/ngx_process.c b/src/os/win32/ngx_process.c index e57adb484..08d9c0ecf 100644 --- a/src/os/win32/ngx_process.c +++ b/src/os/win32/ngx_process.c @@ -85,7 +85,7 @@ ngx_spawn_process(ngx_cycle_t *cycle, char *name, ngx_int_t respawn) rc = WaitForMultipleObjects(2, events, 0, 5000); - ngx_time_update(0, 0); + ngx_time_update(0); ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, "WaitForMultipleObjects: %ul", rc); diff --git a/src/os/win32/ngx_process_cycle.c b/src/os/win32/ngx_process_cycle.c index e3b513a1c..e4e92b85c 100644 --- a/src/os/win32/ngx_process_cycle.c +++ b/src/os/win32/ngx_process_cycle.c @@ -140,7 +140,7 @@ ngx_master_process_cycle(ngx_cycle_t *cycle) ev = WaitForMultipleObjects(nev, events, 0, timeout); err = ngx_errno; - ngx_time_update(0, 0); + ngx_time_update(0); ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, "master WaitForMultipleObjects: %ul", ev); @@ -679,7 +679,7 @@ ngx_worker_process_cycle(ngx_cycle_t *cycle, char *mevn) ev = WaitForMultipleObjects(3, events, 0, INFINITE); err = ngx_errno; - ngx_time_update(0, 0); + ngx_time_update(0); ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "worker WaitForMultipleObjects: %ul", ev); @@ -738,7 +738,7 @@ ngx_worker_process_cycle(ngx_cycle_t *cycle, char *mevn) ev = WaitForMultipleObjects(nev, events, 0, INFINITE); err = ngx_errno; - ngx_time_update(0, 0); + ngx_time_update(0); ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "worker exit WaitForMultipleObjects: %ul", ev); @@ -907,7 +907,7 @@ ngx_cache_manager_thread(void *data) ev = WaitForMultipleObjects(2, events, 0, INFINITE); err = ngx_errno; - ngx_time_update(0, 0); + ngx_time_update(0); ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, "cache manager WaitForMultipleObjects: %ul", ev); @@ -968,7 +968,7 @@ ngx_cache_manager_process_handler(void) next = (n <= next) ? n : next; - ngx_time_update(0, 0); + ngx_time_update(0); } } @@ -980,7 +980,7 @@ ngx_cache_manager_process_handler(void) if (ev != WAIT_TIMEOUT) { - ngx_time_update(0, 0); + ngx_time_update(0); ngx_log_debug1(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0, "cache manager WaitForSingleObject: %ul", ev); @@ -1008,7 +1008,7 @@ ngx_cache_loader_thread(void *data) if (path[i]->loader) { path[i]->loader(path[i]->data); - ngx_time_update(0, 0); + ngx_time_update(0); } } |