diff --git a/include/common/hathreads.h b/include/common/hathreads.h index 0cd00fb00..74a47619c 100644 --- a/include/common/hathreads.h +++ b/include/common/hathreads.h @@ -388,7 +388,6 @@ enum lock_label { TASK_WQ_LOCK, POOL_LOCK, LISTENER_LOCK, - LISTENER_QUEUE_LOCK, PROXY_LOCK, SERVER_LOCK, LBPRM_LOCK, @@ -505,7 +504,6 @@ static inline const char *lock_label(enum lock_label label) case TASK_WQ_LOCK: return "TASK_WQ"; case POOL_LOCK: return "POOL"; case LISTENER_LOCK: return "LISTENER"; - case LISTENER_QUEUE_LOCK: return "LISTENER_QUEUE"; case PROXY_LOCK: return "PROXY"; case SERVER_LOCK: return "SERVER"; case LBPRM_LOCK: return "LBPRM"; diff --git a/src/listener.c b/src/listener.c index 504cbbf38..8512ed054 100644 --- a/src/listener.c +++ b/src/listener.c @@ -42,9 +42,6 @@ #include #include - /* listner_queue lock (same for global and per proxy queues) */ -__decl_spinlock(lq_lock); - /* List head of all known bind keywords */ static struct bind_kw_list bind_keywords = { .list = LIST_HEAD_INIT(bind_keywords.list) @@ -265,11 +262,7 @@ static void disable_listener(struct listener *listener) goto end; if (listener->state == LI_READY) fd_stop_recv(listener->fd); - if (listener->state == LI_LIMITED) { - HA_SPIN_LOCK(LISTENER_QUEUE_LOCK, &lq_lock); - LIST_DEL(&listener->wait_queue); - HA_SPIN_UNLOCK(LISTENER_QUEUE_LOCK, &lq_lock); - } + LIST_DEL_LOCKED(&listener->wait_queue); listener->state = LI_LISTEN; end: HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock); @@ -305,11 +298,7 @@ int pause_listener(struct listener *l) goto end; } - if (l->state == LI_LIMITED) { - HA_SPIN_LOCK(LISTENER_QUEUE_LOCK, &lq_lock); - LIST_DEL(&l->wait_queue); - HA_SPIN_UNLOCK(LISTENER_QUEUE_LOCK, &lq_lock); - } + LIST_DEL_LOCKED(&l->wait_queue); fd_stop_recv(l->fd); l->state = LI_PAUSED; @@ -328,7 +317,7 @@ int pause_listener(struct listener *l) * stopped it. If the resume fails, 0 is returned and an error might be * displayed. */ -static int __resume_listener(struct listener *l) +int resume_listener(struct listener *l) { int ret = 1; @@ -369,8 +358,7 @@ static int __resume_listener(struct listener *l) if (l->state == LI_READY) goto end; - if (l->state == LI_LIMITED) - LIST_DEL(&l->wait_queue); + LIST_DEL_LOCKED(&l->wait_queue); if (l->nbconn >= l->maxconn) { l->state = LI_FULL; @@ -384,16 +372,6 @@ static int __resume_listener(struct listener *l) return ret; } -int resume_listener(struct listener *l) -{ - int ret; - - HA_SPIN_LOCK(LISTENER_QUEUE_LOCK, &lq_lock); - ret = __resume_listener(l); - HA_SPIN_UNLOCK(LISTENER_QUEUE_LOCK, &lq_lock); - return ret; -} - /* Marks a ready listener as full so that the stream code tries to re-enable * it upon next close() using resume_listener(). */ @@ -401,11 +379,7 @@ static void listener_full(struct listener *l) { HA_SPIN_LOCK(LISTENER_LOCK, &l->lock); if (l->state >= LI_READY) { - if (l->state == LI_LIMITED) { - HA_SPIN_LOCK(LISTENER_QUEUE_LOCK, &lq_lock); - LIST_DEL(&l->wait_queue); - HA_SPIN_UNLOCK(LISTENER_QUEUE_LOCK, &lq_lock); - } + LIST_DEL_LOCKED(&l->wait_queue); if (l->state != LI_FULL) { fd_stop_recv(l->fd); l->state = LI_FULL; @@ -421,9 +395,7 @@ static void limit_listener(struct listener *l, struct list *list) { HA_SPIN_LOCK(LISTENER_LOCK, &l->lock); if (l->state == LI_READY) { - HA_SPIN_LOCK(LISTENER_QUEUE_LOCK, &lq_lock); - LIST_ADDQ(list, &l->wait_queue); - HA_SPIN_UNLOCK(LISTENER_QUEUE_LOCK, &lq_lock); + LIST_ADDQ_LOCKED(list, &l->wait_queue); fd_stop_recv(l->fd); l->state = LI_LIMITED; } @@ -462,17 +434,14 @@ int disable_all_listeners(struct protocol *proto) /* Dequeues all of the listeners waiting for a resource in wait queue . */ void dequeue_all_listeners(struct list *list) { - struct listener *listener, *l_back; + struct listener *listener; - HA_SPIN_LOCK(LISTENER_QUEUE_LOCK, &lq_lock); - list_for_each_entry_safe(listener, l_back, list, wait_queue) { + while ((listener = LIST_POP_LOCKED(list, struct listener *, wait_queue))) { /* This cannot fail because the listeners are by definition in - * the LI_LIMITED state. The function also removes the entry - * from the queue. + * the LI_LIMITED state. */ - __resume_listener(listener); + resume_listener(listener); } - HA_SPIN_UNLOCK(LISTENER_QUEUE_LOCK, &lq_lock); } /* Must be called with the lock held. Depending on value, it does @@ -483,11 +452,7 @@ void do_unbind_listener(struct listener *listener, int do_close) if (listener->state == LI_READY) fd_stop_recv(listener->fd); - if (listener->state == LI_LIMITED) { - HA_SPIN_LOCK(LISTENER_QUEUE_LOCK, &lq_lock); - LIST_DEL(&listener->wait_queue); - HA_SPIN_UNLOCK(LISTENER_QUEUE_LOCK, &lq_lock); - } + LIST_DEL_LOCKED(&listener->wait_queue); if (listener->state >= LI_PAUSED) { if (do_close) { @@ -569,6 +534,7 @@ int create_listeners(struct bind_conf *bc, const struct sockaddr_storage *ss, l->fd = fd; memcpy(&l->addr, ss, sizeof(*ss)); + LIST_INIT(&l->wait_queue); l->state = LI_INIT; proto->add(l, port);