mirror of
https://github.com/nginx/nginx.git
synced 2024-12-18 21:23:36 -06:00
Cancelable timers are now preserved if there are other timers.
There is no need to cancel timers early if there are other timers blocking shutdown anyway. Preserving such timers allows nginx to continue some periodic work till the shutdown is actually possible. With the new approach, timers with ev->cancelable are simply ignored when checking if there are any timers left during shutdown.
This commit is contained in:
parent
0212c7fac1
commit
1a58418ae7
@ -96,43 +96,31 @@ ngx_event_expire_timers(void)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ngx_event_cancel_timers(void)
|
||||
ngx_int_t
|
||||
ngx_event_no_timers_left(void)
|
||||
{
|
||||
ngx_event_t *ev;
|
||||
ngx_rbtree_node_t *node, *root, *sentinel;
|
||||
|
||||
sentinel = ngx_event_timer_rbtree.sentinel;
|
||||
root = ngx_event_timer_rbtree.root;
|
||||
|
||||
for ( ;; ) {
|
||||
root = ngx_event_timer_rbtree.root;
|
||||
|
||||
if (root == sentinel) {
|
||||
return;
|
||||
}
|
||||
|
||||
node = ngx_rbtree_min(root, sentinel);
|
||||
if (root == sentinel) {
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
for (node = ngx_rbtree_min(root, sentinel);
|
||||
node;
|
||||
node = ngx_rbtree_next(&ngx_event_timer_rbtree, node))
|
||||
{
|
||||
ev = (ngx_event_t *) ((char *) node - offsetof(ngx_event_t, timer));
|
||||
|
||||
if (!ev->cancelable) {
|
||||
return;
|
||||
return NGX_AGAIN;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/* only cancelable timers left */
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
@ -22,7 +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);
|
||||
ngx_int_t ngx_event_no_timers_left(void);
|
||||
|
||||
|
||||
extern ngx_rbtree_t ngx_event_timer_rbtree;
|
||||
|
@ -738,10 +738,7 @@ ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
|
||||
for ( ;; ) {
|
||||
|
||||
if (ngx_exiting) {
|
||||
ngx_event_cancel_timers();
|
||||
|
||||
if (ngx_event_timer_rbtree.root == ngx_event_timer_rbtree.sentinel)
|
||||
{
|
||||
if (ngx_event_no_timers_left() == NGX_OK) {
|
||||
ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting");
|
||||
|
||||
ngx_worker_process_exit(cycle);
|
||||
|
@ -782,11 +782,7 @@ ngx_worker_thread(void *data)
|
||||
while (!ngx_quit) {
|
||||
|
||||
if (ngx_exiting) {
|
||||
ngx_event_cancel_timers();
|
||||
|
||||
if (ngx_event_timer_rbtree.root
|
||||
== ngx_event_timer_rbtree.sentinel)
|
||||
{
|
||||
if (ngx_event_no_timers_left() == NGX_OK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user