-
Notifications
You must be signed in to change notification settings - Fork 208
/
ngx_time.h
75 lines (51 loc) · 1.86 KB
/
ngx_time.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// annotated by chrono since 2016
/*
* Copyright (C) Igor Sysoev
* Copyright (C) Nginx, Inc.
*/
#ifndef _NGX_TIME_H_INCLUDED_
#define _NGX_TIME_H_INCLUDED_
#include <ngx_config.h>
#include <ngx_core.h>
// 毫秒的整数类型,用于红黑树实现定时器
// ngx_msec_t = ngx_uint_t (ngx_config.h)
// ngx_msec_int_t = ngx_int_t (ngx_config.h)
typedef ngx_rbtree_key_t ngx_msec_t;
typedef ngx_rbtree_key_int_t ngx_msec_int_t;
// 重定义标准C里的tm结构
typedef struct tm ngx_tm_t;
// 重定义tm里的各个成员,加了ngx前缀
#define ngx_tm_sec tm_sec
#define ngx_tm_min tm_min
#define ngx_tm_hour tm_hour
#define ngx_tm_mday tm_mday
#define ngx_tm_mon tm_mon
#define ngx_tm_year tm_year
#define ngx_tm_wday tm_wday
#define ngx_tm_isdst tm_isdst
// 重定义时间相关的类型
#define ngx_tm_sec_t int
#define ngx_tm_min_t int
#define ngx_tm_hour_t int
#define ngx_tm_mday_t int
#define ngx_tm_mon_t int
#define ngx_tm_year_t int
#define ngx_tm_wday_t int
#if (NGX_HAVE_GMTOFF)
#define ngx_tm_gmtoff tm_gmtoff
#define ngx_tm_zone tm_zone
#endif
#if (NGX_SOLARIS)
#define ngx_timezone(isdst) (- (isdst ? altzone : timezone) / 60)
#else
#define ngx_timezone(isdst) (- (isdst ? timezone + 3600 : timezone) / 60)
#endif
void ngx_timezone_update(void);
void ngx_localtime(time_t s, ngx_tm_t *tm);
void ngx_libc_localtime(time_t s, struct tm *tm);
void ngx_libc_gmtime(time_t s, struct tm *tm);
// 这里的宏后面多了一个分号,但此函数很少被外部调用,所以不影响
#define ngx_gettimeofday(tp) (void) gettimeofday(tp, NULL);
#define ngx_msleep(ms) (void) usleep(ms * 1000)
#define ngx_sleep(s) (void) sleep(s)
#endif /* _NGX_TIME_H_INCLUDED_ */