MEDIUM: connections: Attempt to get idle connections from other threads.

In connect_server(), if we no longer have any idle connections for the
current thread, attempt to use the new "takeover" mux method to steal a
connection from another thread.
This should have no impact right now, given no mux implements it.
diff --git a/include/proto/connection.h b/include/proto/connection.h
index 65c99a1..f05a452 100644
--- a/include/proto/connection.h
+++ b/include/proto/connection.h
@@ -477,7 +477,8 @@
 	if (conn->idle_time > 0) {
 		struct server *srv = __objt_server(conn->target);
 		_HA_ATOMIC_SUB(&srv->curr_idle_conns, 1);
-		srv->curr_idle_thr[tid]--;
+		_HA_ATOMIC_SUB(conn->flags & CO_FL_SAFE_LIST ? &srv->curr_safe_nb : &srv->curr_idle_nb, 1);
+		_HA_ATOMIC_SUB(&srv->curr_idle_thr[tid], 1);
 	}
 
 	conn_force_unsubscribe(conn);
diff --git a/include/proto/server.h b/include/proto/server.h
index 7ba9c83..6eb4515 100644
--- a/include/proto/server.h
+++ b/include/proto/server.h
@@ -262,11 +262,16 @@
 			return 0;
 		}
 		MT_LIST_DEL(&conn->list);
-		conn->flags = (conn->flags &~ CO_FL_LIST_MASK) |
-		              (is_safe ? CO_FL_SAFE_LIST : CO_FL_IDLE_LIST);
-		MT_LIST_ADDQ(is_safe ? &srv->safe_conns[tid] : &srv->idle_conns[tid],
-		             (struct mt_list *)&conn->list);
-		srv->curr_idle_thr[tid]++;
+		if (is_safe) {
+			conn->flags = (conn->flags & ~CO_FL_LIST_MASK) | CO_FL_SAFE_LIST;
+			MT_LIST_ADDQ(&srv->safe_conns[tid], (struct mt_list *)&conn->list);
+			_HA_ATOMIC_ADD(&srv->curr_safe_nb, 1);
+		} else {
+			conn->flags = (conn->flags & ~CO_FL_LIST_MASK) | CO_FL_IDLE_LIST;
+			MT_LIST_ADDQ(&srv->idle_conns[tid], (struct mt_list *)&conn->list);
+			_HA_ATOMIC_ADD(&srv->curr_idle_nb, 1);
+		}
+		_HA_ATOMIC_ADD(&srv->curr_idle_thr[tid], 1);
 
 		conn->idle_time = now_ms;
 		__ha_barrier_full();
diff --git a/include/types/server.h b/include/types/server.h
index c29fd18..0ffebb4 100644
--- a/include/types/server.h
+++ b/include/types/server.h
@@ -227,7 +227,9 @@
 	struct list *available_conns;           /* Connection in used, but with still new streams available */
 	unsigned int pool_purge_delay;          /* Delay before starting to purge the idle conns pool */
 	unsigned int max_idle_conns;            /* Max number of connection allowed in the orphan connections list */
-	unsigned int curr_idle_conns;           /* Current number of orphan idling connections */
+	unsigned int curr_idle_conns;           /* Current number of orphan idling connections, both the idle and the safe lists */
+	unsigned int curr_idle_nb;              /* Current number of connections in the idle list */
+	unsigned int curr_safe_nb;              /* Current number of connections in the safe list */
 	unsigned int *curr_idle_thr;            /* Current number of orphan idling connections per thread */
 	int max_reuse;                          /* Max number of requests on a same connection */
 	struct eb32_node idle_node;             /* When to next do cleanup in the idle connections */