[nginx] Core: added the ngx_rbtree_data() macro.

Vladimir Homutov vl at nginx.com
Mon Jun 21 14:59:02 UTC 2021


details:   https://hg.nginx.org/nginx/rev/0c5e84096d99
branches:  
changeset: 7875:0c5e84096d99
user:      Vladimir Homutov <vl at nginx.com>
date:      Mon Jun 21 09:42:43 2021 +0300
description:
Core: added the ngx_rbtree_data() macro.

diffstat:

 src/core/ngx_rbtree.h       |  3 +++
 src/core/ngx_resolver.c     |  4 +---
 src/event/ngx_event_timer.c |  4 ++--
 3 files changed, 6 insertions(+), 5 deletions(-)

diffs (48 lines):

diff -r d1079d6b2f19 -r 0c5e84096d99 src/core/ngx_rbtree.h
--- a/src/core/ngx_rbtree.h	Fri Jun 18 04:00:21 2021 +0300
+++ b/src/core/ngx_rbtree.h	Mon Jun 21 09:42:43 2021 +0300
@@ -47,6 +47,9 @@ struct ngx_rbtree_s {
     (tree)->sentinel = s;                                                     \
     (tree)->insert = i
 
+#define ngx_rbtree_data(node, type, link)                                     \
+    (type *) ((u_char *) (node) - offsetof(type, link))
+
 
 void ngx_rbtree_insert(ngx_rbtree_t *tree, ngx_rbtree_node_t *node);
 void ngx_rbtree_delete(ngx_rbtree_t *tree, ngx_rbtree_node_t *node);
diff -r d1079d6b2f19 -r 0c5e84096d99 src/core/ngx_resolver.c
--- a/src/core/ngx_resolver.c	Fri Jun 18 04:00:21 2021 +0300
+++ b/src/core/ngx_resolver.c	Mon Jun 21 09:42:43 2021 +0300
@@ -51,9 +51,7 @@ typedef struct {
 } ngx_resolver_an_t;
 
 
-#define ngx_resolver_node(n)                                                 \
-    (ngx_resolver_node_t *)                                                  \
-        ((u_char *) (n) - offsetof(ngx_resolver_node_t, node))
+#define ngx_resolver_node(n)  ngx_rbtree_data(n, ngx_resolver_node_t, node)
 
 
 static ngx_int_t ngx_udp_connect(ngx_resolver_connection_t *rec);
diff -r d1079d6b2f19 -r 0c5e84096d99 src/event/ngx_event_timer.c
--- a/src/event/ngx_event_timer.c	Fri Jun 18 04:00:21 2021 +0300
+++ b/src/event/ngx_event_timer.c	Mon Jun 21 09:42:43 2021 +0300
@@ -73,7 +73,7 @@ ngx_event_expire_timers(void)
             return;
         }
 
-        ev = (ngx_event_t *) ((char *) node - offsetof(ngx_event_t, timer));
+        ev = ngx_rbtree_data(node, ngx_event_t, timer);
 
         ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
                        "event timer del: %d: %M",
@@ -113,7 +113,7 @@ ngx_event_no_timers_left(void)
          node;
          node = ngx_rbtree_next(&ngx_event_timer_rbtree, node))
     {
-        ev = (ngx_event_t *) ((char *) node - offsetof(ngx_event_t, timer));
+        ev = ngx_rbtree_data(node, ngx_event_t, timer);
 
         if (!ev->cancelable) {
             return NGX_AGAIN;


More information about the nginx-devel mailing list