tp = ngx_timeofday();
tp->sec = 0;
- ngx_time_update(0);
+ ngx_time_update();
log = old_cycle->log;
volatile ngx_str_t ngx_cached_http_time;
volatile ngx_str_t ngx_cached_http_log_time;
-#if !(NGX_HAVE_GETTIMEZONE)
+#if !(NGX_WIN32)
/*
* locatime() and localtime_r() are not Async-Signal-Safe functions, therefore,
- * if ngx_time_update() is called by signal handler, it uses the cached
+ * they must not be called by a signal handler, so we use the cached
* GMT offset value. Fortunately the value is changed only two times a year.
*/
ngx_cached_time = &cached_time[0];
- ngx_time_update(0);
+ ngx_time_update();
}
void
-ngx_time_update(ngx_uint_t use_cached_gmtoff)
+ngx_time_update(void)
{
u_char *p0, *p1, *p2;
ngx_tm_t tm, gmt;
tp->gmtoff = ngx_gettimezone();
ngx_gmtime(sec + tp->gmtoff * 60, &tm);
-#else
-
- if (use_cached_gmtoff) {
- ngx_gmtime(sec + cached_gmtoff * 60, &tm);
+#elif (NGX_HAVE_GMTOFF)
- } else {
- ngx_localtime(sec, &tm);
+ ngx_localtime(sec, &tm);
+ cached_gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60);
+ tp->gmtoff = cached_gmtoff;
-#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);
+ cached_gmtoff = ngx_timezone(tm.ngx_tm_isdst);
tp->gmtoff = cached_gmtoff;
#endif
}
+#if !(NGX_WIN32)
+
+void
+ngx_time_sigsafe_update(void)
+{
+ u_char *p;
+ ngx_tm_t tm;
+ time_t sec;
+ ngx_uint_t msec;
+ ngx_time_t *tp;
+ struct timeval tv;
+
+ if (!ngx_trylock(&ngx_time_lock)) {
+ return;
+ }
+
+ ngx_gettimeofday(&tv);
+
+ sec = tv.tv_sec;
+ msec = tv.tv_usec / 1000;
+
+ tp = &cached_time[slot];
+
+ if (tp->sec == sec) {
+ ngx_unlock(&ngx_time_lock);
+ return;
+ }
+
+ if (slot == NGX_TIME_SLOTS - 1) {
+ slot = 0;
+ } else {
+ slot++;
+ }
+
+ ngx_gmtime(sec + cached_gmtoff * 60, &tm);
+
+ p = &cached_err_log_time[slot][0];
+
+ (void) ngx_sprintf(p, "%4d/%02d/%02d %02d:%02d:%02d",
+ tm.ngx_tm_year, tm.ngx_tm_mon,
+ tm.ngx_tm_mday, tm.ngx_tm_hour,
+ tm.ngx_tm_min, tm.ngx_tm_sec);
+
+ ngx_memory_barrier();
+
+ ngx_cached_err_log_time.data = p;
+
+ ngx_unlock(&ngx_time_lock);
+}
+
+#endif
+
+
u_char *
ngx_http_time(u_char *buf, time_t t)
{
void ngx_time_init(void);
-void ngx_time_update(ngx_uint_t use_cached_gmtoff);
+void ngx_time_update(void);
+void ngx_time_sigsafe_update(void);
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);
err = (events == -1) ? ngx_errno : 0;
if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
- ngx_time_update(0);
+ ngx_time_update();
}
if (err) {
err = (events == -1) ? ngx_errno : 0;
if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
- ngx_time_update(0);
+ ngx_time_update();
}
if (err) {
err = ngx_errno;
if (flags & NGX_UPDATE_TIME) {
- ngx_time_update(0);
+ ngx_time_update();
}
if (n == -1) {
for (i = 0; i < events; i++) {
if (event_list[i].portev_source == PORT_SOURCE_TIMER) {
- ngx_time_update(0);
+ ngx_time_update();
continue;
}
for ( ;; ) {
Sleep(timer);
- ngx_time_update(0);
+ ngx_time_update();
#if 1
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0, "timer");
#endif
delta = ngx_current_msec;
if (flags & NGX_UPDATE_TIME) {
- ngx_time_update(0);
+ ngx_time_update();
}
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
err = (events == -1) ? ngx_errno : 0;
if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
- ngx_time_update(0);
+ ngx_time_update();
}
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
#if (NGX_HAVE_TIMER_EVENT)
if (event_list[i].filter == EVFILT_TIMER) {
- ngx_time_update(0);
+ ngx_time_update();
continue;
}
err = (ready == -1) ? ngx_errno : 0;
if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
- ngx_time_update(0);
+ ngx_time_update();
}
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"rtsig signo:%d", signo);
if (flags & NGX_UPDATE_TIME) {
- ngx_time_update(0);
+ ngx_time_update();
}
if (err == NGX_EAGAIN) {
signo, si.si_fd, si.si_band);
if (flags & NGX_UPDATE_TIME) {
- ngx_time_update(0);
+ ngx_time_update();
}
rtscf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_rtsig_module);
} else if (signo == SIGALRM) {
- ngx_time_update(0);
+ ngx_time_update();
return NGX_OK;
}
if (flags & NGX_UPDATE_TIME) {
- ngx_time_update(0);
+ ngx_time_update();
}
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
err = (ready == -1) ? ngx_errno : 0;
if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
- ngx_time_update(0);
+ ngx_time_update();
}
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
err = (ready == -1) ? ngx_socket_errno : 0;
if (flags & NGX_UPDATE_TIME) {
- ngx_time_update(0);
+ ngx_time_update();
}
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
if (cache->files++ > 100) {
- ngx_time_update(0);
+ ngx_time_update();
elapsed = ngx_abs((ngx_msec_int_t) (ngx_current_msec - cache->last));
ngx_msleep(200);
- ngx_time_update(0);
+ ngx_time_update();
}
cache->last = ngx_current_msec;
}
}
- ngx_time_update(1);
+ ngx_time_sigsafe_update();
action = "";
sigsuspend(&set);
- ngx_time_update(0);
+ ngx_time_update();
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"wake up, sigio %i", sigio);
next = (n <= next) ? n : next;
- ngx_time_update(0);
+ ngx_time_update();
}
}
if (path[i]->loader) {
path[i]->loader(path[i]->data);
- ngx_time_update(0);
+ ngx_time_update();
}
}
rc = WaitForMultipleObjects(2, events, 0, 5000);
- ngx_time_update(0);
+ ngx_time_update();
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
"WaitForMultipleObjects: %ul", rc);
ev = WaitForMultipleObjects(nev, events, 0, timeout);
err = ngx_errno;
- ngx_time_update(0);
+ ngx_time_update();
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
"master WaitForMultipleObjects: %ul", ev);
ev = WaitForMultipleObjects(3, events, 0, INFINITE);
err = ngx_errno;
- ngx_time_update(0);
+ ngx_time_update();
ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0,
"worker WaitForMultipleObjects: %ul", ev);
ev = WaitForMultipleObjects(nev, events, 0, INFINITE);
err = ngx_errno;
- ngx_time_update(0);
+ ngx_time_update();
ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0,
"worker exit WaitForMultipleObjects: %ul", ev);
ev = WaitForMultipleObjects(2, events, 0, INFINITE);
err = ngx_errno;
- ngx_time_update(0);
+ ngx_time_update();
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
"cache manager WaitForMultipleObjects: %ul", ev);
next = (n <= next) ? n : next;
- ngx_time_update(0);
+ ngx_time_update();
}
}
if (ev != WAIT_TIMEOUT) {
- ngx_time_update(0);
+ ngx_time_update();
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0,
"cache manager WaitForSingleObject: %ul", ev);
if (path[i]->loader) {
path[i]->loader(path[i]->data);
- ngx_time_update(0);
+ ngx_time_update();
}
}