Mercurial > hg > nginx
comparison src/core/ngx_times.c @ 266:5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 23 Feb 2004 20:57:12 +0000 |
parents | e6c005b66b3a |
children | 7bb9562216ce |
comparison
equal
deleted
inserted
replaced
265:6468241715e6 | 266:5238e93961a1 |
---|---|
1 | 1 |
2 #include <ngx_config.h> | 2 #include <ngx_config.h> |
3 #include <ngx_core.h> | 3 #include <ngx_core.h> |
4 | |
5 | |
6 #if (NGX_THREADS) | |
7 static ngx_mutex_t *ngx_time_mutex; | |
8 #endif | |
4 | 9 |
5 | 10 |
6 time_t ngx_cached_time; | 11 time_t ngx_cached_time; |
7 ngx_epoch_msec_t ngx_elapsed_msec; | 12 ngx_epoch_msec_t ngx_elapsed_msec; |
8 ngx_epoch_msec_t ngx_old_elapsed_msec; | 13 ngx_epoch_msec_t ngx_old_elapsed_msec; |
44 ngx_start_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000; | 49 ngx_start_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000; |
45 ngx_old_elapsed_msec = 0; | 50 ngx_old_elapsed_msec = 0; |
46 ngx_elapsed_msec = 0; | 51 ngx_elapsed_msec = 0; |
47 | 52 |
48 ngx_time_update(tv.tv_sec); | 53 ngx_time_update(tv.tv_sec); |
54 | |
55 #if (NGX_THREADS0) | |
56 if (!(ngx_time_mutex = ngx_mutex_init(log, NGX_MUTEX_LIGHT); | |
57 return 0; | |
58 } | |
59 #endif | |
60 | |
49 } | 61 } |
50 | 62 |
51 | 63 |
52 void ngx_time_update(time_t s) | 64 void ngx_time_update(time_t s) |
53 { | 65 { |
54 ngx_tm_t tm; | 66 ngx_tm_t tm; |
55 | 67 |
56 if (ngx_cached_time == s) { | 68 if (ngx_cached_time == s) { |
57 return; | 69 return; |
58 } | 70 } |
71 | |
72 #if (NGX_THREADS0) | |
73 if (ngx_mutex_trylock(ngx_time_mutex) != NGX_OK) { | |
74 return; | |
75 } | |
76 #endif | |
59 | 77 |
60 ngx_cached_time = s; | 78 ngx_cached_time = s; |
61 | 79 |
62 ngx_gmtime(ngx_cached_time, &ngx_cached_gmtime); | 80 ngx_gmtime(ngx_cached_time, &ngx_cached_gmtime); |
63 | 81 |
88 months[tm.ngx_tm_mon - 1], | 106 months[tm.ngx_tm_mon - 1], |
89 tm.ngx_tm_year, | 107 tm.ngx_tm_year, |
90 tm.ngx_tm_hour, | 108 tm.ngx_tm_hour, |
91 tm.ngx_tm_min, | 109 tm.ngx_tm_min, |
92 tm.ngx_tm_sec); | 110 tm.ngx_tm_sec); |
111 | |
112 #if (NGX_THREADS0) | |
113 ngx_mutex_unlock(ngx_time_mutex); | |
114 #endif | |
115 | |
93 } | 116 } |
94 | 117 |
95 | 118 |
96 size_t ngx_http_time(char *buf, time_t t) | 119 size_t ngx_http_time(char *buf, time_t t) |
97 { | 120 { |