Mercurial > hg > nginx-quic
annotate src/event/ngx_event_timer.h @ 3167:7d1f9a449603
we do not need to increase request counter in this place,
the bug had appeared in r3115
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 28 Sep 2009 11:12:45 +0000 |
parents | 1739becf3f83 |
children | d620f497c50f |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
371
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
371
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
371
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
371
diff
changeset
|
5 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
371
diff
changeset
|
6 |
50
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #ifndef _NGX_EVENT_TIMER_H_INCLUDED_ |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #define _NGX_EVENT_TIMER_H_INCLUDED_ |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 #include <ngx_config.h> |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
12 #include <ngx_core.h> |
50
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
13 #include <ngx_event.h> |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
14 |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 |
501 | 16 #define NGX_TIMER_INFINITE (ngx_msec_t) -1 |
270
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
17 |
493 | 18 #define NGX_TIMER_LAZY_DELAY 300 |
19 | |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
20 |
270
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
21 ngx_int_t ngx_event_timer_init(ngx_log_t *log); |
206
9aa426375256
nginx-0.0.1-2003-12-05-10:11:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
205
diff
changeset
|
22 ngx_msec_t ngx_event_find_timer(void); |
557 | 23 void ngx_event_expire_timers(void); |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
24 |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
25 |
270
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
26 #if (NGX_THREADS) |
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
27 extern ngx_mutex_t *ngx_event_timer_mutex; |
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
28 #endif |
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
29 |
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
30 |
559 | 31 extern ngx_thread_volatile ngx_rbtree_t ngx_event_timer_rbtree; |
207
6e0fef527732
nginx-0.0.1-2003-12-05-20:07:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
206
diff
changeset
|
32 |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
33 |
493 | 34 static ngx_inline void |
35 ngx_event_del_timer(ngx_event_t *ev) | |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
36 { |
214
e0c502f15852
nginx-0.0.1-2003-12-22-12:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
37 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
557 | 38 "event timer del: %d: %M", |
559 | 39 ngx_event_ident(ev->data), ev->timer.key); |
213
f536f91e8e99
nginx-0.0.1-2003-12-19-15:45:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
210
diff
changeset
|
40 |
563 | 41 ngx_mutex_lock(ngx_event_timer_mutex); |
270
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
42 |
559 | 43 ngx_rbtree_delete(&ngx_event_timer_rbtree, &ev->timer); |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
44 |
270
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
45 ngx_mutex_unlock(ngx_event_timer_mutex); |
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
46 |
214
e0c502f15852
nginx-0.0.1-2003-12-22-12:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
47 #if (NGX_DEBUG) |
559 | 48 ev->timer.left = NULL; |
49 ev->timer.right = NULL; | |
50 ev->timer.parent = NULL; | |
214
e0c502f15852
nginx-0.0.1-2003-12-22-12:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
51 #endif |
e0c502f15852
nginx-0.0.1-2003-12-22-12:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
52 |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
53 ev->timer_set = 0; |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
54 } |
50
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
55 |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
56 |
493 | 57 static ngx_inline void |
58 ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer) | |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
59 { |
561 | 60 ngx_msec_t key; |
61 ngx_msec_int_t diff; | |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
62 |
563 | 63 key = ngx_current_msec + timer; |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
64 |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
275
diff
changeset
|
65 if (ev->timer_set) { |
304
bcbe876f4262
nginx-0.0.3-2004-04-02-09:14:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
66 |
bcbe876f4262
nginx-0.0.3-2004-04-02-09:14:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
67 /* |
1807 | 68 * Use a previous timer value if difference between it and a new |
69 * value is less than NGX_TIMER_LAZY_DELAY milliseconds: this allows | |
70 * to minimize the rbtree operations for fast connections. | |
304
bcbe876f4262
nginx-0.0.3-2004-04-02-09:14:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
71 */ |
bcbe876f4262
nginx-0.0.3-2004-04-02-09:14:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
72 |
561 | 73 diff = (ngx_msec_int_t) (key - ev->timer.key); |
557 | 74 |
75 if (ngx_abs(diff) < NGX_TIMER_LAZY_DELAY) { | |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
275
diff
changeset
|
76 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
557 | 77 "event timer: %d, old: %M, new: %M", |
559 | 78 ngx_event_ident(ev->data), ev->timer.key, key); |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
275
diff
changeset
|
79 return; |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
275
diff
changeset
|
80 } |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
275
diff
changeset
|
81 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
275
diff
changeset
|
82 ngx_del_timer(ev); |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
275
diff
changeset
|
83 } |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
275
diff
changeset
|
84 |
559 | 85 ev->timer.key = key; |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
275
diff
changeset
|
86 |
557 | 87 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
88 "event timer add: %d: %M:%M", | |
559 | 89 ngx_event_ident(ev->data), timer, ev->timer.key); |
213
f536f91e8e99
nginx-0.0.1-2003-12-19-15:45:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
210
diff
changeset
|
90 |
563 | 91 ngx_mutex_lock(ngx_event_timer_mutex); |
270
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
92 |
559 | 93 ngx_rbtree_insert(&ngx_event_timer_rbtree, &ev->timer); |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
94 |
270
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
95 ngx_mutex_unlock(ngx_event_timer_mutex); |
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
96 |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
97 ev->timer_set = 1; |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
98 } |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
99 |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
100 |
59
e8cdc2989cee
nginx-0.0.1-2003-02-06-20:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
53
diff
changeset
|
101 #endif /* _NGX_EVENT_TIMER_H_INCLUDED_ */ |