Klaus Demo nginx / 2f916a9
*) 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 Igor Sysoev 12 years ago
17 changed file(s) with 65 addition(s) and 46 deletion(s). Raw diff Collapse all Expand all
6262 tp = ngx_timeofday();
6363 tp->sec = 0;
6464
65 ngx_time_update(0, 0);
65 ngx_time_update(0);
6666
6767
6868 log = old_cycle->log;
2727 volatile ngx_str_t ngx_cached_http_time;
2828 volatile ngx_str_t ngx_cached_http_log_time;
2929
30 #if !(NGX_HAVE_GETTIMEZONE)
31
32 /*
33 * locatime() and localtime_r() are not Async-Signal-Safe functions, therefore,
34 * if ngx_time_update() is called by signal handler, it uses the cached
35 * GMT offset value. Fortunately the value is changed only two times a year.
36 */
37
38 static ngx_int_t cached_gmtoff;
39 #endif
40
3041 static ngx_time_t cached_time[NGX_TIME_SLOTS];
3142 static u_char cached_err_log_time[NGX_TIME_SLOTS]
3243 [sizeof("1970/09/28 12:00:00")];
4960
5061 ngx_cached_time = &cached_time[0];
5162
52 ngx_time_update(0, 0);
63 ngx_time_update(0);
5364 }
5465
5566
5667 void
57 ngx_time_update(time_t sec, ngx_uint_t msec)
68 ngx_time_update(ngx_uint_t use_cached_gmtoff)
5869 {
5970 u_char *p0, *p1, *p2;
6071 ngx_tm_t tm, gmt;
72 time_t sec;
73 ngx_uint_t msec;
6174 ngx_time_t *tp;
6275 struct timeval tv;
6376
6578 return;
6679 }
6780
68 if (sec == 0) {
69 ngx_gettimeofday(&tv);
70
71 sec = tv.tv_sec;
72 msec = tv.tv_usec / 1000;
73 }
81 ngx_gettimeofday(&tv);
82
83 sec = tv.tv_sec;
84 msec = tv.tv_usec / 1000;
7485
7586 ngx_current_msec = (ngx_msec_t) sec * 1000 + msec;
7687
108119 tp->gmtoff = ngx_gettimezone();
109120 ngx_gmtime(sec + tp->gmtoff * 60, &tm);
110121
111 #elif (NGX_HAVE_GMTOFF)
112
113 ngx_localtime(sec, &tm);
114 tp->gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60);
115
116122 #else
117123
118 ngx_localtime(sec, &tm);
119 tp->gmtoff = ngx_timezone(tm.ngx_tm_isdst);
124 if (use_cached_gmtoff) {
125 ngx_gmtime(sec + cached_gmtoff * 60, &tm);
126
127 } else {
128 ngx_localtime(sec, &tm);
129
130 #if (NGX_HAVE_GMTOFF)
131 cached_gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60);
132 #else
133 cached_gmtoff = ngx_timezone(tm.ngx_tm_isdst);
134 #endif
135
136 }
137
138 tp->gmtoff = cached_gmtoff;
120139
121140 #endif
122141
1919
2020
2121 void ngx_time_init(void);
22 void ngx_time_update(time_t sec, ngx_uint_t msec);
22 void ngx_time_update(ngx_uint_t use_cached_gmtoff);
2323 u_char *ngx_http_time(u_char *buf, time_t t);
2424 u_char *ngx_http_cookie_time(u_char *buf, time_t t);
2525 void ngx_gmtime(time_t t, ngx_tm_t *tp);
371371 err = (events == -1) ? ngx_errno : 0;
372372
373373 if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
374 ngx_time_update(0, 0);
374 ngx_time_update(0);
375375 }
376376
377377 if (err) {
531531 err = (events == -1) ? ngx_errno : 0;
532532
533533 if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
534 ngx_time_update(0, 0);
534 ngx_time_update(0);
535535 }
536536
537537 if (err) {
404404 err = ngx_errno;
405405
406406 if (flags & NGX_UPDATE_TIME) {
407 ngx_time_update(0, 0);
407 ngx_time_update(0);
408408 }
409409
410410 if (n == -1) {
438438 for (i = 0; i < events; i++) {
439439
440440 if (event_list[i].portev_source == PORT_SOURCE_TIMER) {
441 ngx_time_update(0, 0);
441 ngx_time_update(0);
442442 continue;
443443 }
444444
162162 for ( ;; ) {
163163 Sleep(timer);
164164
165 ngx_time_update(0, 0);
165 ngx_time_update(0);
166166 #if 1
167167 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0, "timer");
168168 #endif
257257 delta = ngx_current_msec;
258258
259259 if (flags & NGX_UPDATE_TIME) {
260 ngx_time_update(0, 0);
260 ngx_time_update(0);
261261 }
262262
263263 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
537537 err = (events == -1) ? ngx_errno : 0;
538538
539539 if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
540 ngx_time_update(0, 0);
540 ngx_time_update(0);
541541 }
542542
543543 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
588588 #if (NGX_HAVE_TIMER_EVENT)
589589
590590 if (event_list[i].filter == EVFILT_TIMER) {
591 ngx_time_update(0, 0);
591 ngx_time_update(0);
592592 continue;
593593 }
594594
262262 err = (ready == -1) ? ngx_errno : 0;
263263
264264 if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
265 ngx_time_update(0, 0);
265 ngx_time_update(0);
266266 }
267267
268268 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
322322 "rtsig signo:%d", signo);
323323
324324 if (flags & NGX_UPDATE_TIME) {
325 ngx_time_update(0, 0);
325 ngx_time_update(0);
326326 }
327327
328328 if (err == NGX_EAGAIN) {
348348 signo, si.si_fd, si.si_band);
349349
350350 if (flags & NGX_UPDATE_TIME) {
351 ngx_time_update(0, 0);
351 ngx_time_update(0);
352352 }
353353
354354 rtscf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_rtsig_module);
418418
419419 } else if (signo == SIGALRM) {
420420
421 ngx_time_update(0, 0);
421 ngx_time_update(0);
422422
423423 return NGX_OK;
424424
670670 }
671671
672672 if (flags & NGX_UPDATE_TIME) {
673 ngx_time_update(0, 0);
673 ngx_time_update(0);
674674 }
675675
676676 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
262262 err = (ready == -1) ? ngx_errno : 0;
263263
264264 if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) {
265 ngx_time_update(0, 0);
265 ngx_time_update(0);
266266 }
267267
268268 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
268268 err = (ready == -1) ? ngx_socket_errno : 0;
269269
270270 if (flags & NGX_UPDATE_TIME) {
271 ngx_time_update(0, 0);
271 ngx_time_update(0);
272272 }
273273
274274 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
12151215
12161216 if (cache->files++ > 100) {
12171217
1218 ngx_time_update(0, 0);
1218 ngx_time_update(0);
12191219
12201220 elapsed = ngx_abs((ngx_msec_int_t) (ngx_current_msec - cache->last));
12211221
12321232
12331233 ngx_msleep(200);
12341234
1235 ngx_time_update(0, 0);
1235 ngx_time_update(0);
12361236 }
12371237
12381238 cache->last = ngx_current_msec;
316316 }
317317 }
318318
319 ngx_time_update(0, 0);
319 ngx_time_update(1);
320320
321321 action = "";
322322
167167
168168 sigsuspend(&set);
169169
170 ngx_time_update(0, 0);
170 ngx_time_update(0);
171171
172172 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
173173 "wake up, sigio %i", sigio);
13411341
13421342 next = (n <= next) ? n : next;
13431343
1344 ngx_time_update(0, 0);
1344 ngx_time_update(0);
13451345 }
13461346 }
13471347
13711371
13721372 if (path[i]->loader) {
13731373 path[i]->loader(path[i]->data);
1374 ngx_time_update(0, 0);
1374 ngx_time_update(0);
13751375 }
13761376 }
13771377
8484
8585 rc = WaitForMultipleObjects(2, events, 0, 5000);
8686
87 ngx_time_update(0, 0);
87 ngx_time_update(0);
8888
8989 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
9090 "WaitForMultipleObjects: %ul", rc);
139139 ev = WaitForMultipleObjects(nev, events, 0, timeout);
140140
141141 err = ngx_errno;
142 ngx_time_update(0, 0);
142 ngx_time_update(0);
143143
144144 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
145145 "master WaitForMultipleObjects: %ul", ev);
678678 ev = WaitForMultipleObjects(3, events, 0, INFINITE);
679679
680680 err = ngx_errno;
681 ngx_time_update(0, 0);
681 ngx_time_update(0);
682682
683683 ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0,
684684 "worker WaitForMultipleObjects: %ul", ev);
737737 ev = WaitForMultipleObjects(nev, events, 0, INFINITE);
738738
739739 err = ngx_errno;
740 ngx_time_update(0, 0);
740 ngx_time_update(0);
741741
742742 ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0,
743743 "worker exit WaitForMultipleObjects: %ul", ev);
906906 ev = WaitForMultipleObjects(2, events, 0, INFINITE);
907907
908908 err = ngx_errno;
909 ngx_time_update(0, 0);
909 ngx_time_update(0);
910910
911911 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
912912 "cache manager WaitForMultipleObjects: %ul", ev);
967967
968968 next = (n <= next) ? n : next;
969969
970 ngx_time_update(0, 0);
970 ngx_time_update(0);
971971 }
972972 }
973973
979979
980980 if (ev != WAIT_TIMEOUT) {
981981
982 ngx_time_update(0, 0);
982 ngx_time_update(0);
983983
984984 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0,
985985 "cache manager WaitForSingleObject: %ul", ev);
10071007
10081008 if (path[i]->loader) {
10091009 path[i]->loader(path[i]->data);
1010 ngx_time_update(0, 0);
1010 ngx_time_update(0);
10111011 }
10121012 }
10131013