From: Willy Tarreau Date: Wed, 23 Jun 2021 13:08:06 +0000 (+0200) Subject: MINOR: queue: add queue_init() to initialize a queue X-Git-Tag: v2.5-dev1~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=df3b0cbe31bdb15495a040437496cbdff5d494d4;p=thirdparty%2Fhaproxy.git MINOR: queue: add queue_init() to initialize a queue This is better and cleaner than open-coding this in the server and proxy code, where it has all chances of becoming wrong once forgotten. --- diff --git a/include/haproxy/queue.h b/include/haproxy/queue.h index 101a4ca5f6..3e79507876 100644 --- a/include/haproxy/queue.h +++ b/include/haproxy/queue.h @@ -109,6 +109,13 @@ static inline int queue_limit_offset(int offset) return offset; } +static inline void queue_init(struct queue *queue) +{ + queue->head = EB_ROOT; + queue->length = 0; + queue->idx = 0; + HA_SPIN_INIT(&queue->lock); +} #endif /* _HAPROXY_QUEUE_H */ diff --git a/src/proxy.c b/src/proxy.c index 98a46fd5b3..3c679509c0 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -1292,8 +1292,7 @@ void init_new_proxy(struct proxy *p) { memset(p, 0, sizeof(struct proxy)); p->obj_type = OBJ_TYPE_PROXY; - p->queue.head = EB_ROOT; - HA_SPIN_INIT(&p->queue.lock); + queue_init(&p->queue); LIST_INIT(&p->acl); LIST_INIT(&p->http_req_rules); LIST_INIT(&p->http_res_rules); diff --git a/src/server.c b/src/server.c index 2b3cc82bed..95a479d339 100644 --- a/src/server.c +++ b/src/server.c @@ -2160,8 +2160,7 @@ struct server *new_server(struct proxy *proxy) srv->obj_type = OBJ_TYPE_SERVER; srv->proxy = proxy; - srv->queue.head = EB_ROOT; - HA_SPIN_INIT(&srv->queue.lock); + queue_init(&srv->queue); LIST_APPEND(&servers_list, &srv->global_list); LIST_INIT(&srv->srv_rec_item); LIST_INIT(&srv->ip_rec_item);