Mercurial > hg > nginx-quic
annotate src/event/ngx_event_timer.c @ 182:3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 13 Nov 2003 06:14:05 +0000 |
parents | e92c2c647c57 |
children | 8dee38ea9117 |
rev | line source |
---|---|
50
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
49
diff
changeset
|
1 |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
49
diff
changeset
|
2 #include <ngx_config.h> |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
49
diff
changeset
|
3 #include <ngx_core.h> |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
49
diff
changeset
|
4 #include <ngx_event.h> |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
49
diff
changeset
|
5 |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
49
diff
changeset
|
6 |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
7 /* TODO: in multithreaded enviroment all timer operations must be |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
114
diff
changeset
|
8 protected by the single mutex */ |
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
114
diff
changeset
|
9 |
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
114
diff
changeset
|
10 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
11 static ngx_event_t *ngx_timer_queue, ngx_temp_timer_queue; |
53
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
12 static int ngx_timer_cur_queue; |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
13 static int ngx_timer_queue_num; |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
14 static int ngx_expire_timers; |
49
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
16 |
113
d7f606e25b99
nginx-0.0.1-2003-07-04-19:10:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
17 int ngx_event_timer_init(ngx_cycle_t *cycle) |
49
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
18 { |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
19 int i; |
105
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
20 ngx_event_t *new_queue; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
21 ngx_event_conf_t *ecf; |
50
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
49
diff
changeset
|
22 |
113
d7f606e25b99
nginx-0.0.1-2003-07-04-19:10:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
23 ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module); |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
24 |
105
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
25 if (ngx_timer_queue_num < ecf->timer_queues) { |
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
26 ngx_test_null(new_queue, |
113
d7f606e25b99
nginx-0.0.1-2003-07-04-19:10:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
27 ngx_alloc(ecf->timer_queues * sizeof(ngx_event_t), |
d7f606e25b99
nginx-0.0.1-2003-07-04-19:10:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
28 cycle->log), |
105
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
29 NGX_ERROR); |
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
30 |
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
31 for (i = 0; i < ngx_timer_queue_num; i++) { |
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
32 new_queue[i] = ngx_timer_queue[i]; |
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
33 } |
50
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
49
diff
changeset
|
34 |
105
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
35 if (ngx_timer_queue) { |
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
36 ngx_free(ngx_timer_queue); |
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
37 } |
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
38 |
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
39 ngx_timer_queue = new_queue; |
50
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
49
diff
changeset
|
40 |
105
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
41 ngx_timer_queue_num = ecf->timer_queues; |
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
42 ngx_timer_cur_queue = 0; |
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
43 |
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
44 for (/* void */; i < ngx_timer_queue_num; i++) { |
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
45 ngx_timer_queue[i].timer_prev = &ngx_timer_queue[i]; |
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
46 ngx_timer_queue[i].timer_next = &ngx_timer_queue[i]; |
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
47 } |
113
d7f606e25b99
nginx-0.0.1-2003-07-04-19:10:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
48 |
d7f606e25b99
nginx-0.0.1-2003-07-04-19:10:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
49 } else if (ngx_timer_queue_num > ecf->timer_queues) { |
d7f606e25b99
nginx-0.0.1-2003-07-04-19:10:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
50 /* STUB */ |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
51 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "NOT READY: timer"); |
113
d7f606e25b99
nginx-0.0.1-2003-07-04-19:10:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
52 exit(1); |
50
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
49
diff
changeset
|
53 } |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
49
diff
changeset
|
54 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
55 ngx_temp_timer_queue.timer_prev = &ngx_temp_timer_queue; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
56 ngx_temp_timer_queue.timer_next = &ngx_temp_timer_queue; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
57 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
58 return NGX_OK;; |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
59 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
60 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
61 |
113
d7f606e25b99
nginx-0.0.1-2003-07-04-19:10:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
62 void ngx_event_timer_done(ngx_cycle_t *cycle) |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
63 { |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
64 ngx_free(ngx_timer_queue); |
105
00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
65 ngx_timer_queue = NULL; |
113
d7f606e25b99
nginx-0.0.1-2003-07-04-19:10:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
66 ngx_timer_queue_num = 0; |
50
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
49
diff
changeset
|
67 } |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
49
diff
changeset
|
68 |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
49
diff
changeset
|
69 |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
49
diff
changeset
|
70 void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer) |
b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
49
diff
changeset
|
71 { |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
72 ngx_event_t *e, *queue; |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
73 #if (NGX_DEBUG_EVENT) |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
74 ngx_connection_t *c; |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
75 #endif |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
76 |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
77 if (ev->timer_set) { |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
78 ngx_del_timer(ev); |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
79 } |
49
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
80 |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
81 #if (NGX_DEBUG_EVENT) |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
82 c = ev->data; |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
83 ngx_log_debug(ev->log, "set timer: %d:%d:%d, slot: %d" _ |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
84 c->fd _ ev->write _ timer _ ngx_timer_cur_queue); |
49
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
85 #endif |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
86 |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
87 if (ev->timer_next || ev->timer_prev) { |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
88 ngx_log_error(NGX_LOG_ALERT, ev->log, 0, "timer already set"); |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
89 return; |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
90 } |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
91 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
92 if (ngx_expire_timers) { |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
93 queue = &ngx_temp_timer_queue; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
94 |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
95 } else { |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
96 queue = &ngx_timer_queue[ngx_timer_cur_queue++]; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
97 |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
98 if (ngx_timer_cur_queue >= ngx_timer_queue_num) { |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
99 ngx_timer_cur_queue = 0; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
100 } |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
101 } |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
102 |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
103 for (e = queue->timer_next; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
104 e != queue && timer > e->timer_delta; |
49
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
105 e = e->timer_next) |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
106 { |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
107 timer -= e->timer_delta; |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
108 } |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
109 |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
110 ev->timer_delta = timer; |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
111 |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
112 ev->timer_next = e; |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
113 ev->timer_prev = e->timer_prev; |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
114 |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
115 e->timer_prev->timer_next = ev; |
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
116 e->timer_prev = ev; |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
117 |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
118 ev->timer_set = 1; |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
119 |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
120 return; |
49
c091d5b853c8
nginx-0.0.1-2003-01-21-20:36:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
121 } |
51
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
122 |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
123 |
53
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
124 int ngx_event_find_timer(void) |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
125 { |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
126 int i; |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
127 ngx_msec_t timer; |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
128 |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
129 timer = NGX_MAX_MSEC; |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
130 |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
131 for (i = 0; i < ngx_timer_queue_num; i++) { |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
132 if (ngx_timer_queue[i].timer_next == &ngx_timer_queue[i]) { |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
133 continue; |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
134 } |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
135 |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
136 if (timer > ngx_timer_queue[i].timer_next->timer_delta) { |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
137 timer = ngx_timer_queue[i].timer_next->timer_delta; |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
138 } |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
139 } |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
140 |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
141 if (timer == NGX_MAX_MSEC) { |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
142 return 0; |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
143 } |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
144 |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
145 return timer; |
53
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
146 } |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
147 |
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
148 |
51
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
149 void ngx_event_expire_timers(ngx_msec_t timer) |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
150 { |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
151 int i; |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
152 ngx_msec_t delta; |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
153 ngx_event_t *ev; |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
154 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
155 ngx_expire_timers = 1; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
156 |
53
d1e42f1b8fd4
nginx-0.0.1-2003-01-27-00:08:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
52
diff
changeset
|
157 for (i = 0; i < ngx_timer_queue_num; i++) { |
51
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
158 |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
159 delta = timer; |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
160 |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
161 for ( ;; ) { |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
162 ev = ngx_timer_queue[i].timer_next; |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
163 |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
164 if (ev == &ngx_timer_queue[i]) { |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
165 break; |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
166 } |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
167 |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
168 if (ev->timer_delta > delta) { |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
169 ev->timer_delta -= delta; |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
170 break; |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
171 } |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
172 |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
173 delta -= ev->timer_delta; |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
174 |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
175 ngx_del_timer(ev); |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
176 |
77
57c2e18d3572
nginx-0.0.1-2003-04-17-21:59:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
53
diff
changeset
|
177 if (ev->delayed) { |
57c2e18d3572
nginx-0.0.1-2003-04-17-21:59:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
53
diff
changeset
|
178 ev->delayed = 0; |
57c2e18d3572
nginx-0.0.1-2003-04-17-21:59:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
53
diff
changeset
|
179 if (ev->ready == 0) { |
57c2e18d3572
nginx-0.0.1-2003-04-17-21:59:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
53
diff
changeset
|
180 continue; |
57c2e18d3572
nginx-0.0.1-2003-04-17-21:59:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
53
diff
changeset
|
181 } |
57c2e18d3572
nginx-0.0.1-2003-04-17-21:59:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
53
diff
changeset
|
182 |
57c2e18d3572
nginx-0.0.1-2003-04-17-21:59:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
53
diff
changeset
|
183 } else { |
57c2e18d3572
nginx-0.0.1-2003-04-17-21:59:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
53
diff
changeset
|
184 ev->timedout = 1; |
57c2e18d3572
nginx-0.0.1-2003-04-17-21:59:35 import
Igor Sysoev <igor@sysoev.ru>
parents:
53
diff
changeset
|
185 } |
51
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
186 |
87
5f6d848dcbef
nginx-0.0.1-2003-05-13-20:02:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
187 ev->event_handler(ev); |
51
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
188 } |
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
189 } |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
190 |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
191 ngx_expire_timers = 0; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
192 |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
193 if (ngx_temp_timer_queue.timer_next == &ngx_temp_timer_queue) { |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
194 return; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
195 } |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
196 |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
197 timer = 0; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
198 |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
199 while (ngx_temp_timer_queue.timer_next != &ngx_temp_timer_queue) { |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
200 timer += ngx_temp_timer_queue.timer_next->timer_delta; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
201 ev = ngx_temp_timer_queue.timer_next; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
202 |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
203 #if (NGX_DEBUG_EVENT) |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
204 ngx_log_debug(ev->log, "process temp timer queue"); |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
205 #endif |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
206 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
207 ngx_del_timer(ev); |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
208 ngx_add_timer(ev, timer); |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
209 } |
51
a6afbb8a2ada
nginx-0.0.1-2003-01-24-09:20:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
50
diff
changeset
|
210 } |