mirror of
https://github.com/nginx/nginx.git
synced 2024-12-20 06:03:31 -06:00
nginx-0.0.1-2003-01-24-09:20:47 import
This commit is contained in:
parent
fcce8d529a
commit
404326f68f
@ -175,6 +175,22 @@ int ngx_kqueue_process_events(ngx_log_t *log)
|
|||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
struct timespec ts, *tp;
|
struct timespec ts, *tp;
|
||||||
|
|
||||||
|
timer = ngx_event_find_timer();
|
||||||
|
|
||||||
|
if (timer) {
|
||||||
|
ts.tv_sec = timer / 1000;
|
||||||
|
ts.tv_nsec = (timer % 1000) * 1000000;
|
||||||
|
tp = &ts;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
delta = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
timer = 0;
|
||||||
|
delta = 0;
|
||||||
|
tp = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
if (timer_queue.timer_next != &timer_queue) {
|
if (timer_queue.timer_next != &timer_queue) {
|
||||||
timer = timer_queue.timer_next->timer_delta;
|
timer = timer_queue.timer_next->timer_delta;
|
||||||
ts.tv_sec = timer / 1000;
|
ts.tv_sec = timer / 1000;
|
||||||
@ -188,6 +204,7 @@ int ngx_kqueue_process_events(ngx_log_t *log)
|
|||||||
delta = 0;
|
delta = 0;
|
||||||
tp = NULL;
|
tp = NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if (NGX_DEBUG_EVENT)
|
#if (NGX_DEBUG_EVENT)
|
||||||
ngx_log_debug(log, "kevent timer: %d" _ timer);
|
ngx_log_debug(log, "kevent timer: %d" _ timer);
|
||||||
@ -267,6 +284,11 @@ int ngx_kqueue_process_events(ngx_log_t *log)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (timer) {
|
||||||
|
ngx_event_expire_timers(delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
if (timer && timer_queue.timer_next != &timer_queue) {
|
if (timer && timer_queue.timer_next != &timer_queue) {
|
||||||
if (delta >= timer_queue.timer_next->timer_delta) {
|
if (delta >= timer_queue.timer_next->timer_delta) {
|
||||||
for ( ;; ) {
|
for ( ;; ) {
|
||||||
@ -289,6 +311,7 @@ int ngx_kqueue_process_events(ngx_log_t *log)
|
|||||||
timer_queue.timer_next->timer_delta -= delta;
|
timer_queue.timer_next->timer_delta -= delta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,9 @@ void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
n = timer % ngx_timer_hash_size;
|
n = timer % ngx_timer_hash_size;
|
||||||
|
#if (NGX_DEBUG_EVENT)
|
||||||
|
ngx_log_debug(ev->log, "timer slot: %d" _ n);
|
||||||
|
#endif
|
||||||
|
|
||||||
for (e = ngx_timer_queue[n].timer_next;
|
for (e = ngx_timer_queue[n].timer_next;
|
||||||
e != &ngx_timer_queue[n] && timer > e->timer_delta;
|
e != &ngx_timer_queue[n] && timer > e->timer_delta;
|
||||||
@ -67,3 +70,38 @@ void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer)
|
|||||||
e->timer_prev->timer_next = ev;
|
e->timer_prev->timer_next = ev;
|
||||||
e->timer_prev = ev;
|
e->timer_prev = ev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ngx_event_expire_timers(ngx_msec_t timer)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
ngx_msec_t delta;
|
||||||
|
ngx_event_t *ev;
|
||||||
|
|
||||||
|
for (i = 0; i < ngx_timer_hash_size; i++) {
|
||||||
|
|
||||||
|
delta = timer;
|
||||||
|
|
||||||
|
for ( ;; ) {
|
||||||
|
ev = ngx_timer_queue[i].timer_next;
|
||||||
|
|
||||||
|
if (ev == &ngx_timer_queue[i]) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ev->timer_delta > delta) {
|
||||||
|
ev->timer_delta -= delta;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
delta -= ev->timer_delta;
|
||||||
|
|
||||||
|
ngx_del_timer(ev);
|
||||||
|
ev->timedout = 1;
|
||||||
|
|
||||||
|
if (ev->event_handler(ev) == NGX_ERROR) {
|
||||||
|
ev->close_handler(ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -16,7 +16,7 @@ extern ngx_event_t *ngx_timer_queue;
|
|||||||
extern int ngx_timer_hash_size;
|
extern int ngx_timer_hash_size;
|
||||||
|
|
||||||
|
|
||||||
ngx_inline static int ngx_event_get_timer()
|
ngx_inline static int ngx_event_find_timer()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
ngx_msec_t timer;
|
ngx_msec_t timer;
|
||||||
@ -24,10 +24,12 @@ ngx_inline static int ngx_event_get_timer()
|
|||||||
timer = NGX_MAX_MSEC;
|
timer = NGX_MAX_MSEC;
|
||||||
|
|
||||||
for (i = 0; i < ngx_timer_hash_size; i++) {
|
for (i = 0; i < ngx_timer_hash_size; i++) {
|
||||||
if (ngx_timer_queue[i].timer_next != &ngx_timer_queue[i]) {
|
if (ngx_timer_queue[i].timer_next == &ngx_timer_queue[i]) {
|
||||||
if (timer > ngx_timer_queue[i].timer_next->timer_delta) {
|
continue;
|
||||||
timer = ngx_timer_queue[i].timer_next->timer_delta;
|
}
|
||||||
}
|
|
||||||
|
if (timer > ngx_timer_queue[i].timer_next->timer_delta) {
|
||||||
|
timer = ngx_timer_queue[i].timer_next->timer_delta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user