From: Willy Tarreau Date: Tue, 18 Mar 2025 10:30:37 +0000 (+0100) Subject: MINOR: server: simplify srv_has_streams() X-Git-Tag: v3.2-dev8~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0e8c573b4b0c41dff15dcec02a82c23a64862b7d;p=thirdparty%2Fhaproxy.git MINOR: server: simplify srv_has_streams() Now that thanks to commit c880c32b16 ("MINOR: stream: decrement srv->served after detaching from the list") we can trust srv->served, let's use it and no longer loop on threads when checking if a server still has streams attached to it. This will be much cheaper and will result in keeping isolation for a shorter time in the "wait" command. --- diff --git a/src/server.c b/src/server.c index 051dd984a..9fa7dfb33 100644 --- a/src/server.c +++ b/src/server.c @@ -2005,18 +2005,10 @@ static int srv_parse_strict_maxconn(char **args, int *cur_arg, struct proxy *px, return 0; } -/* Returns 1 if the server has streams pointing to it, and 0 otherwise. - * - * Must be called with the server lock held. - */ +/* Returns 1 if the server has streams pointing to it, and 0 otherwise. */ static int srv_has_streams(struct server *srv) { - int thr; - - for (thr = 0; thr < global.nbthread; thr++) - if (!MT_LIST_ISEMPTY(&srv->per_thr[thr].streams)) - return 1; - return 0; + return !!_HA_ATOMIC_LOAD(&srv->served); } /* Shutdown all connections of a server. The caller must pass a termination