Events: introduced cancelable timers.

This commit is contained in:
Valentin Bartenev 2014-08-13 22:45:04 +04:00
parent 16403bc7b1
commit 8b30fb7c97
5 changed files with 49 additions and 0 deletions

View File

@ -136,6 +136,8 @@ struct ngx_event_s {
unsigned channel:1;
unsigned resolver:1;
unsigned cancelable:1;
#if 0

View File

@ -94,3 +94,45 @@ ngx_event_expire_timers(void)
ev->handler(ev);
}
}
void
ngx_event_cancel_timers(void)
{
ngx_event_t *ev;
ngx_rbtree_node_t *node, *root, *sentinel;
sentinel = ngx_event_timer_rbtree.sentinel;
for ( ;; ) {
root = ngx_event_timer_rbtree.root;
if (root == sentinel) {
return;
}
node = ngx_rbtree_min(root, sentinel);
ev = (ngx_event_t *) ((char *) node - offsetof(ngx_event_t, timer));
if (!ev->cancelable) {
return;
}
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
"event timer cancel: %d: %M",
ngx_event_ident(ev->data), ev->timer.key);
ngx_rbtree_delete(&ngx_event_timer_rbtree, &ev->timer);
#if (NGX_DEBUG)
ev->timer.left = NULL;
ev->timer.right = NULL;
ev->timer.parent = NULL;
#endif
ev->timer_set = 0;
ev->handler(ev);
}
}

View File

@ -22,6 +22,7 @@
ngx_int_t ngx_event_timer_init(ngx_log_t *log);
ngx_msec_t ngx_event_find_timer(void);
void ngx_event_expire_timers(void);
void ngx_event_cancel_timers(void);
extern ngx_rbtree_t ngx_event_timer_rbtree;

View File

@ -809,6 +809,8 @@ ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
}
}
ngx_event_cancel_timers();
if (ngx_event_timer_rbtree.root == ngx_event_timer_rbtree.sentinel)
{
ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting");

View File

@ -821,6 +821,8 @@ ngx_worker_thread(void *data)
}
}
ngx_event_cancel_timers();
if (ngx_event_timer_rbtree.root
== ngx_event_timer_rbtree.sentinel)
{