diff options
author | Valentin Bartenev <vbart@nginx.com> | 2014-08-13 22:45:04 +0400 |
---|---|---|
committer | Valentin Bartenev <vbart@nginx.com> | 2014-08-13 22:45:04 +0400 |
commit | 8b30fb7c9771e24543f7fcc82431a4741f6e9d48 (patch) | |
tree | 69f8e8934be7aaffabad7b9a41693e6a5a87f63d /src/event/ngx_event_timer.c | |
parent | 16403bc7b1af41433bfcd1bda4db8216b57e0810 (diff) |
Events: introduced cancelable timers.
Diffstat (limited to 'src/event/ngx_event_timer.c')
-rw-r--r-- | src/event/ngx_event_timer.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/event/ngx_event_timer.c b/src/event/ngx_event_timer.c index b7f2ade38..8f547b215 100644 --- a/src/event/ngx_event_timer.c +++ b/src/event/ngx_event_timer.c @@ -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); + } +} |