diff options
author | Igor Sysoev <igor@sysoev.ru> | 2003-12-05 20:07:27 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2003-12-05 20:07:27 +0300 |
commit | 62260f2a158e27e5f6b1689e10dc25ea3c617473 (patch) | |
tree | d37c7d3f837c9f477a5010adedcbe98be89e735c /src/event | |
parent | faca119aa5b2375d247c4948ba6791e7d8d2b8bc (diff) |
nginx-0.0.1-2003-12-05-20:07:27 import
Diffstat (limited to 'src/event')
-rw-r--r-- | src/event/modules/ngx_kqueue_module.c | 20 | ||||
-rw-r--r-- | src/event/ngx_event.h | 15 | ||||
-rw-r--r-- | src/event/ngx_event_timer.c | 20 | ||||
-rw-r--r-- | src/event/ngx_event_timer.h | 6 |
4 files changed, 22 insertions, 39 deletions
diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c index 393c4d1ef..e438ad33c 100644 --- a/src/event/modules/ngx_kqueue_module.c +++ b/src/event/modules/ngx_kqueue_module.c @@ -354,6 +354,7 @@ static int ngx_kqueue_process_events(ngx_log_t *log) struct timespec ts, *tp; timer = ngx_event_find_timer(); + ngx_old_elapsed_msec = ngx_elapsed_msec; if (timer) { ts.tv_sec = timer / 1000; @@ -399,19 +400,6 @@ static int ngx_kqueue_process_events(ngx_log_t *log) if (timer) { delta = ngx_elapsed_msec - delta; -#if 0 - delta = tv.tv_sec * 1000 + tv.tv_usec / 1000 - delta; - - /* - * The expired timers must be handled before a processing of the events - * because the new timers can be added during a processing - */ - - ngx_event_expire_timers((ngx_msec_t) delta); - - ngx_event_set_timer_delta((ngx_msec_t) delta); -#endif - } else { if (events == 0) { ngx_log_error(NGX_LOG_ALERT, log, 0, @@ -519,12 +507,6 @@ static int ngx_kqueue_process_events(ngx_log_t *log) ngx_event_expire_timers((ngx_msec_t) delta); } -#if 0 - if (timer) { - ngx_event_expire_timers((ngx_msec_t) delta); - } -#endif - return NGX_OK; } diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h index 71b280799..c2170250d 100644 --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -22,7 +22,7 @@ typedef struct { struct ngx_event_s { void *data; - /* TODO rename to handler, move flags to struct start */ + /* TODO rename to handler */ void (*event_handler)(ngx_event_t *ev); u_int index; @@ -31,17 +31,14 @@ struct ngx_event_s { ngx_event_t *prev; ngx_event_t *next; -#if 0 - ngx_event_t *timer_prev; - ngx_event_t *timer_next; - - ngx_msec_t timer_delta; -#endif - ngx_log_t *log; /* - * ngx_rbtree_t rbtree; + * The inline of "ngx_rbtree_t rbtree;". + * + * It allows to pack rbtree_color and variuos event bit flags into + * the single int. We also use "unsigned char" and then "usigned short" + * because otherwise MSVC 6.0 uses an additional int for bit flags. */ ngx_int_t rbtree_key; diff --git a/src/event/ngx_event_timer.c b/src/event/ngx_event_timer.c index db97d01fc..90a4f2099 100644 --- a/src/event/ngx_event_timer.c +++ b/src/event/ngx_event_timer.c @@ -5,14 +5,15 @@ ngx_rbtree_t *ngx_event_timer_rbtree; +ngx_rbtree_t ngx_event_timer_sentinel; int ngx_event_timer_init(ngx_cycle_t *cycle) { - ngx_event_timer_rbtree = &sentinel; - sentinel.left = &sentinel; - sentinel.right = &sentinel; - sentinel.parent = &sentinel; + ngx_event_timer_rbtree = &ngx_event_timer_sentinel; + ngx_event_timer_sentinel.left = &ngx_event_timer_sentinel; + ngx_event_timer_sentinel.right = &ngx_event_timer_sentinel; + ngx_event_timer_sentinel.parent = &ngx_event_timer_sentinel; return NGX_OK; } @@ -27,9 +28,9 @@ ngx_msec_t ngx_event_find_timer(void) { ngx_rbtree_t *node; - node = ngx_rbtree_min(ngx_event_timer_rbtree); + node = ngx_rbtree_min(ngx_event_timer_rbtree, &ngx_event_timer_sentinel); - if (node == &sentinel) { + if (node == &ngx_event_timer_sentinel) { return 0; } else { @@ -45,14 +46,15 @@ void ngx_event_expire_timers(ngx_msec_t timer) ngx_rbtree_t *node; for ( ;; ) { - node = ngx_rbtree_min(ngx_event_timer_rbtree); + node = ngx_rbtree_min(ngx_event_timer_rbtree, + &ngx_event_timer_sentinel); - if (node == &sentinel) { + if (node == &ngx_event_timer_sentinel) { break; } if ((ngx_msec_t) node->key <= (ngx_msec_t) - (ngx_elapsed_msec + timer) / NGX_TIMER_RESOLUTION) + (ngx_old_elapsed_msec + timer) / NGX_TIMER_RESOLUTION) { ev = (ngx_event_t *) ((char *) node - offsetof(ngx_event_t, rbtree_key)); diff --git a/src/event/ngx_event_timer.h b/src/event/ngx_event_timer.h index 0985cf1ad..aee06593c 100644 --- a/src/event/ngx_event_timer.h +++ b/src/event/ngx_event_timer.h @@ -35,11 +35,13 @@ void ngx_event_expire_timers(ngx_msec_t timer); extern ngx_rbtree_t *ngx_event_timer_rbtree; +extern ngx_rbtree_t ngx_event_timer_sentinel; + ngx_inline static void ngx_event_del_timer(ngx_event_t *ev) { - ngx_rbtree_delete(&ngx_event_timer_rbtree, + ngx_rbtree_delete(&ngx_event_timer_rbtree, &ngx_event_timer_sentinel, (ngx_rbtree_t *) &ev->rbtree_key); ev->timer_set = 0; @@ -55,7 +57,7 @@ ngx_inline static void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer) ev->rbtree_key = (ngx_int_t) (ngx_elapsed_msec + timer) / NGX_TIMER_RESOLUTION; - ngx_rbtree_insert(&ngx_event_timer_rbtree, + ngx_rbtree_insert(&ngx_event_timer_rbtree, &ngx_event_timer_sentinel, (ngx_rbtree_t *) &ev->rbtree_key); ev->timer_set = 1; |