Mercurial > hg > nginx-quic
comparison src/core/ngx_times.c @ 3474:d4c4cfdffe30
*) 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
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sat, 13 Mar 2010 18:08:07 +0000 |
parents | bf38420c9e25 |
children | ab353d7dc182 |
comparison
equal
deleted
inserted
replaced
3473:0299cf5856fc | 3474:d4c4cfdffe30 |
---|---|
26 volatile ngx_time_t *ngx_cached_time; | 26 volatile ngx_time_t *ngx_cached_time; |
27 volatile ngx_str_t ngx_cached_err_log_time; | 27 volatile ngx_str_t ngx_cached_err_log_time; |
28 volatile ngx_str_t ngx_cached_http_time; | 28 volatile ngx_str_t ngx_cached_http_time; |
29 volatile ngx_str_t ngx_cached_http_log_time; | 29 volatile ngx_str_t ngx_cached_http_log_time; |
30 | 30 |
31 #if !(NGX_HAVE_GETTIMEZONE) | |
32 | |
33 /* | |
34 * locatime() and localtime_r() are not Async-Signal-Safe functions, therefore, | |
35 * if ngx_time_update() is called by signal handler, it uses the cached | |
36 * GMT offset value. Fortunately the value is changed only two times a year. | |
37 */ | |
38 | |
39 static ngx_int_t cached_gmtoff; | |
40 #endif | |
41 | |
31 static ngx_time_t cached_time[NGX_TIME_SLOTS]; | 42 static ngx_time_t cached_time[NGX_TIME_SLOTS]; |
32 static u_char cached_err_log_time[NGX_TIME_SLOTS] | 43 static u_char cached_err_log_time[NGX_TIME_SLOTS] |
33 [sizeof("1970/09/28 12:00:00")]; | 44 [sizeof("1970/09/28 12:00:00")]; |
34 static u_char cached_http_time[NGX_TIME_SLOTS] | 45 static u_char cached_http_time[NGX_TIME_SLOTS] |
35 [sizeof("Mon, 28 Sep 1970 06:00:00 GMT")]; | 46 [sizeof("Mon, 28 Sep 1970 06:00:00 GMT")]; |
48 ngx_cached_http_time.len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1; | 59 ngx_cached_http_time.len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1; |
49 ngx_cached_http_log_time.len = sizeof("28/Sep/1970:12:00:00 +0600") - 1; | 60 ngx_cached_http_log_time.len = sizeof("28/Sep/1970:12:00:00 +0600") - 1; |
50 | 61 |
51 ngx_cached_time = &cached_time[0]; | 62 ngx_cached_time = &cached_time[0]; |
52 | 63 |
53 ngx_time_update(0, 0); | 64 ngx_time_update(0); |
54 } | 65 } |
55 | 66 |
56 | 67 |
57 void | 68 void |
58 ngx_time_update(time_t sec, ngx_uint_t msec) | 69 ngx_time_update(ngx_uint_t use_cached_gmtoff) |
59 { | 70 { |
60 u_char *p0, *p1, *p2; | 71 u_char *p0, *p1, *p2; |
61 ngx_tm_t tm, gmt; | 72 ngx_tm_t tm, gmt; |
73 time_t sec; | |
74 ngx_uint_t msec; | |
62 ngx_time_t *tp; | 75 ngx_time_t *tp; |
63 struct timeval tv; | 76 struct timeval tv; |
64 | 77 |
65 if (!ngx_trylock(&ngx_time_lock)) { | 78 if (!ngx_trylock(&ngx_time_lock)) { |
66 return; | 79 return; |
67 } | 80 } |
68 | 81 |
69 if (sec == 0) { | 82 ngx_gettimeofday(&tv); |
70 ngx_gettimeofday(&tv); | 83 |
71 | 84 sec = tv.tv_sec; |
72 sec = tv.tv_sec; | 85 msec = tv.tv_usec / 1000; |
73 msec = tv.tv_usec / 1000; | |
74 } | |
75 | 86 |
76 ngx_current_msec = (ngx_msec_t) sec * 1000 + msec; | 87 ngx_current_msec = (ngx_msec_t) sec * 1000 + msec; |
77 | 88 |
78 tp = &cached_time[slot]; | 89 tp = &cached_time[slot]; |
79 | 90 |
107 #if (NGX_HAVE_GETTIMEZONE) | 118 #if (NGX_HAVE_GETTIMEZONE) |
108 | 119 |
109 tp->gmtoff = ngx_gettimezone(); | 120 tp->gmtoff = ngx_gettimezone(); |
110 ngx_gmtime(sec + tp->gmtoff * 60, &tm); | 121 ngx_gmtime(sec + tp->gmtoff * 60, &tm); |
111 | 122 |
112 #elif (NGX_HAVE_GMTOFF) | |
113 | |
114 ngx_localtime(sec, &tm); | |
115 tp->gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60); | |
116 | |
117 #else | 123 #else |
118 | 124 |
119 ngx_localtime(sec, &tm); | 125 if (use_cached_gmtoff) { |
120 tp->gmtoff = ngx_timezone(tm.ngx_tm_isdst); | 126 ngx_gmtime(sec + cached_gmtoff * 60, &tm); |
127 | |
128 } else { | |
129 ngx_localtime(sec, &tm); | |
130 | |
131 #if (NGX_HAVE_GMTOFF) | |
132 cached_gmtoff = (ngx_int_t) (tm.ngx_tm_gmtoff / 60); | |
133 #else | |
134 cached_gmtoff = ngx_timezone(tm.ngx_tm_isdst); | |
135 #endif | |
136 | |
137 } | |
138 | |
139 tp->gmtoff = cached_gmtoff; | |
121 | 140 |
122 #endif | 141 #endif |
123 | 142 |
124 | 143 |
125 p1 = &cached_err_log_time[slot][0]; | 144 p1 = &cached_err_log_time[slot][0]; |