diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/nginx.c | 13 | ||||
-rw-r--r-- | src/core/ngx_atomic.h | 13 | ||||
-rw-r--r-- | src/core/ngx_core.h | 3 | ||||
-rw-r--r-- | src/core/ngx_rbtree.c | 91 |
4 files changed, 87 insertions, 33 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index 36a8b4bd8..7deb24fd3 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -72,7 +72,7 @@ int main(int argc, char *const *argv) int i; ngx_fd_t fd; ngx_log_t *log; - ngx_cycle_t *cycle; + ngx_cycle_t *cycle, init_cycle; ngx_open_file_t *file; #if !(WIN32) size_t len; @@ -88,10 +88,19 @@ int main(int argc, char *const *argv) /* TODO */ ngx_max_sockets = -1; ngx_time_init(); +#if (HAVE_PCRE) ngx_regex_init(); +#endif log = ngx_log_init_errlog(); + + /* init_cycle->log is required for signal handlers */ + + ngx_memzero(&init_cycle, sizeof(ngx_cycle_t)); + init_cycle.log = log; + ngx_cycle = &init_cycle; + if (ngx_os_init(log) == NGX_ERROR) { return 1; } @@ -207,7 +216,7 @@ int main(int argc, char *const *argv) } if (rotate) { - ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "rotating logs"); + ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reopen logs"); file = cycle->open_files.elts; for (i = 0; i < cycle->open_files.nelts; i++) { diff --git a/src/core/ngx_atomic.h b/src/core/ngx_atomic.h new file mode 100644 index 000000000..b24a997c4 --- /dev/null +++ b/src/core/ngx_atomic.h @@ -0,0 +1,13 @@ +#ifndef _NGX_ATOMIC_H_INCLUDED_ +#define _NGX_ATOMIC_H_INCLUDED_ + + +#include <ngx_config.h> +#include <ngx_core.h> + + +#define ngx_atomic_inc(x) x++; +#define ngx_atomic_dec(x) x--; + + +#endif /* _NGX_ATOMIC_H_INCLUDED_ */ diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h index b2c3d554d..75658bacb 100644 --- a/src/core/ngx_core.h +++ b/src/core/ngx_core.h @@ -15,6 +15,7 @@ typedef struct ngx_event_s ngx_event_t; typedef struct ngx_connection_s ngx_connection_t; +#include <ngx_atomic.h> #include <ngx_time.h> #include <ngx_socket.h> #include <ngx_errno.h> @@ -30,7 +31,9 @@ typedef struct ngx_connection_s ngx_connection_t; #include <ngx_file.h> #include <ngx_files.h> #include <ngx_crc.h> +#if (HAVE_PCRE) #include <ngx_regex.h> +#endif #include <ngx_rbtree.h> #include <ngx_times.h> #include <ngx_inet.h> diff --git a/src/core/ngx_rbtree.c b/src/core/ngx_rbtree.c index 3e6025f12..dc605510e 100644 --- a/src/core/ngx_rbtree.c +++ b/src/core/ngx_rbtree.c @@ -31,7 +31,7 @@ void ngx_rbtree_insert(ngx_rbtree_t **root, ngx_rbtree_t *sentinel, /* a binary tree insert */ if (*root == sentinel) { - node->parent = sentinel; + node->parent = NULL; node->left = sentinel; node->right = sentinel; ngx_rbt_black(node); @@ -71,7 +71,7 @@ void ngx_rbtree_insert(ngx_rbtree_t **root, ngx_rbtree_t *sentinel, ngx_rbt_red(node); - while (node->parent && ngx_rbt_is_red(node->parent)) { + while (node != *root && ngx_rbt_is_red(node->parent)) { if (node->parent == node->parent->parent->left) { temp = node->parent->parent->right; @@ -123,61 +123,90 @@ void ngx_rbtree_insert(ngx_rbtree_t **root, ngx_rbtree_t *sentinel, void ngx_rbtree_delete(ngx_rbtree_t **root, ngx_rbtree_t *sentinel, ngx_rbtree_t *node) { + ngx_int_t red; ngx_rbtree_t *subst, *temp, *w; /* a binary tree delete */ - if (node->left == sentinel || node->right == sentinel) { + if (node->left == sentinel) { + temp = node->right; subst = node; - } else { - - /* find a node successor */ - - if (node->right == sentinel) { - temp = node; - subst = node->parent; + } else if (node->right == sentinel) { + temp = node->left; + subst = node; - while (subst != sentinel && temp == subst->right) { - temp = subst; - subst = subst->parent; - } + } else { + subst = ngx_rbtree_min(node->right, sentinel); + if (subst->left != sentinel) { + temp = subst->left; } else { - subst = ngx_rbtree_min(node->right, sentinel); + temp = subst->right; } } - if (subst->left != sentinel) { - temp = subst->left; - } else { - temp = subst->right; + if (subst == *root) { + /* it's the last node */ + *root = sentinel; + return; } - temp->parent = subst->parent; + red = ngx_rbt_is_red(subst); - if (subst->parent == sentinel) { - *root = temp; - - } else if (subst == subst->parent->left) { + if (subst == subst->parent->left) { subst->parent->left = temp; } else { subst->parent->right = temp; } - if (subst != node) { - node->key = subst->key; - node->color = subst->color; + if (subst == node) { + + temp->parent = subst->parent; + + } else { + + if (subst->parent == node) { + temp->parent = subst; + + } else { + temp->parent = subst->parent; + } + + subst->left = node->left; + subst->right = node->right; + subst->parent = node->parent; + ngx_rbt_copy_color(subst, node); + + if (node == *root) { + *root = subst; + + } else { + if (node == node->parent->left) { + node->parent->left = subst; + } else { + node->parent->right = subst; + } + } + + if (subst->left != sentinel) { + subst->left->parent = subst; + } + + if (subst->right != sentinel) { + subst->right->parent = subst; + } } - if (ngx_rbt_is_red(subst)) { + if (red) { return; } /* a delete fixup */ - while (temp->parent != sentinel && ngx_rbt_is_black(temp)) { + while (temp != *root && ngx_rbt_is_black(temp)) { + if (temp == temp->parent->left) { w = temp->parent->right; @@ -257,7 +286,7 @@ ngx_inline void ngx_rbtree_left_rotate(ngx_rbtree_t **root, temp->parent = node->parent; - if (node->parent == sentinel) { + if (node == *root) { *root = temp; } else if (node == node->parent->left) { @@ -287,7 +316,7 @@ ngx_inline void ngx_rbtree_right_rotate(ngx_rbtree_t **root, temp->parent = node->parent; - if (node->parent == sentinel) { + if (node == *root) { *root = temp; } else if (node == node->parent->right) { |