]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: queue: add queue_init() to initialize a queue
authorWilly Tarreau <w@1wt.eu>
Wed, 23 Jun 2021 13:08:06 +0000 (15:08 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Jun 2021 08:52:31 +0000 (10:52 +0200)
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.

include/haproxy/queue.h
src/proxy.c
src/server.c

index 101a4ca5f61b696fbd830b15a51077a1d13ae8e8..3e79507876f78b0f6ba9f58e344511fe29f0c3d4 100644 (file)
@@ -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 */
 
index 98a46fd5b38c72dc696e38b59c52f8d6fac866ac..3c679509c034c4c0b823b4023a15fd14f6368c3e 100644 (file)
@@ -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);
index 2b3cc82bed4d175b9d55df985d323862e348564a..95a479d339cab01b56279591dad04914fcb9eb1a 100644 (file)
@@ -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);