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.
This commit is contained in:
Willy Tarreau 2021-06-23 15:08:06 +02:00
parent ae0b12ee03
commit df3b0cbe31
3 changed files with 9 additions and 4 deletions

View File

@ -109,6 +109,13 @@ static inline int queue_limit_offset(int offset)
return 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 */ #endif /* _HAPROXY_QUEUE_H */

View File

@ -1292,8 +1292,7 @@ void init_new_proxy(struct proxy *p)
{ {
memset(p, 0, sizeof(struct proxy)); memset(p, 0, sizeof(struct proxy));
p->obj_type = OBJ_TYPE_PROXY; p->obj_type = OBJ_TYPE_PROXY;
p->queue.head = EB_ROOT; queue_init(&p->queue);
HA_SPIN_INIT(&p->queue.lock);
LIST_INIT(&p->acl); LIST_INIT(&p->acl);
LIST_INIT(&p->http_req_rules); LIST_INIT(&p->http_req_rules);
LIST_INIT(&p->http_res_rules); LIST_INIT(&p->http_res_rules);

View File

@ -2160,8 +2160,7 @@ struct server *new_server(struct proxy *proxy)
srv->obj_type = OBJ_TYPE_SERVER; srv->obj_type = OBJ_TYPE_SERVER;
srv->proxy = proxy; srv->proxy = proxy;
srv->queue.head = EB_ROOT; queue_init(&srv->queue);
HA_SPIN_INIT(&srv->queue.lock);
LIST_APPEND(&servers_list, &srv->global_list); LIST_APPEND(&servers_list, &srv->global_list);
LIST_INIT(&srv->srv_rec_item); LIST_INIT(&srv->srv_rec_item);
LIST_INIT(&srv->ip_rec_item); LIST_INIT(&srv->ip_rec_item);