mirror of
https://github.com/nginx/nginx.git
synced 2024-12-20 06:03:31 -06:00
Events: introduced cancelable timers.
This commit is contained in:
parent
16403bc7b1
commit
8b30fb7c97
@ -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 New Issue
Block a user