nginx-0.0.1-2003-01-24-09:20:47 import

This commit is contained in:
Igor Sysoev 2003-01-24 06:20:47 +00:00
parent fcce8d529a
commit 404326f68f
3 changed files with 68 additions and 5 deletions

View File

@ -175,6 +175,22 @@ int ngx_kqueue_process_events(ngx_log_t *log)
struct timeval tv;
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) {
timer = timer_queue.timer_next->timer_delta;
ts.tv_sec = timer / 1000;
@ -188,6 +204,7 @@ int ngx_kqueue_process_events(ngx_log_t *log)
delta = 0;
tp = NULL;
}
#endif
#if (NGX_DEBUG_EVENT)
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 (delta >= timer_queue.timer_next->timer_delta) {
for ( ;; ) {
@ -289,6 +311,7 @@ int ngx_kqueue_process_events(ngx_log_t *log)
timer_queue.timer_next->timer_delta -= delta;
}
}
#endif
return NGX_OK;
}

View File

@ -51,6 +51,9 @@ void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer)
}
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;
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 = 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);
}
}
}
}

View File

@ -16,7 +16,7 @@ extern ngx_event_t *ngx_timer_queue;
extern int ngx_timer_hash_size;
ngx_inline static int ngx_event_get_timer()
ngx_inline static int ngx_event_find_timer()
{
int i;
ngx_msec_t timer;
@ -24,10 +24,12 @@ ngx_inline static int ngx_event_get_timer()
timer = NGX_MAX_MSEC;
for (i = 0; i < ngx_timer_hash_size; i++) {
if (ngx_timer_queue[i].timer_next != &ngx_timer_queue[i]) {
if (timer > ngx_timer_queue[i].timer_next->timer_delta) {
timer = ngx_timer_queue[i].timer_next->timer_delta;
}
if (ngx_timer_queue[i].timer_next == &ngx_timer_queue[i]) {
continue;
}
if (timer > ngx_timer_queue[i].timer_next->timer_delta) {
timer = ngx_timer_queue[i].timer_next->timer_delta;
}
}