Skip to content

Commit

Permalink
Core: added the ngx_rbtree_data() macro.
Browse files Browse the repository at this point in the history
--HG--
branch : nginx
  • Loading branch information
vlhomutov committed Jun 21, 2021
1 parent 80d8e9f commit 40218c9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/core/ngx_rbtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/core/ngx_resolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/event/ngx_event_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 40218c9

Please sign in to comment.