Events: introduced cancelable timers.
This commit is contained in:
parent
c389fe9249
commit
39a1597ff6
5 changed files with 49 additions and 0 deletions
|
@ -136,6 +136,8 @@ struct ngx_event_s {
|
|||
unsigned channel:1;
|
||||
unsigned resolver:1;
|
||||
|
||||
unsigned cancelable:1;
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -821,6 +821,8 @@ ngx_worker_thread(void *data)
|
|||
}
|
||||
}
|
||||
|
||||
ngx_event_cancel_timers();
|
||||
|
||||
if (ngx_event_timer_rbtree.root
|
||||
== ngx_event_timer_rbtree.sentinel)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue