From 484093df805400222ac795eba21128df2e1a0228 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 3 Feb 2023 14:53:34 +0100 Subject: [PATCH] CLEANUP: listener/config: remove the special case for shards==1 In fact this case is already handled by the regular shards code, there is no need to special-case it. --- src/cfgparse.c | 71 +++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/src/cfgparse.c b/src/cfgparse.c index 75d0b5664f..fc8c7f2ba4 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -2968,52 +2968,47 @@ int check_config_validity() /* apply thread masks and groups to all receivers */ list_for_each_entry(li, &bind_conf->listeners, by_bind) { - if (bind_conf->settings.shards <= 1) { - li->rx.bind_thread = thread_set_first_tmask(&bind_conf->thread_set); - li->rx.bind_tgroup = thread_set_first_group(&bind_conf->thread_set); - } else { - struct listener *new_li; - int shard, shards, todo, done, bit; - ulong mask; + struct listener *new_li; + int shard, shards, todo, done, bit; + ulong mask; - shards = bind_conf->settings.shards; - todo = my_popcountl(thread_set_first_tmask(&bind_conf->thread_set)); + shards = bind_conf->settings.shards; + todo = my_popcountl(thread_set_first_tmask(&bind_conf->thread_set)); - /* no more shards than total threads */ - if (shards > todo) - shards = todo; + /* no more shards than total threads */ + if (shards > todo) + shards = todo; - shard = done = bit = 0; - new_li = li; + shard = done = bit = 0; + new_li = li; - while (1) { - mask = 0; - while (done < todo) { - /* enlarge mask to cover next bit of bind_thread */ - while (!(thread_set_first_tmask(&bind_conf->thread_set) & (1UL << bit))) - bit++; - mask |= (1UL << bit); + while (1) { + mask = 0; + while (done < todo) { + /* enlarge mask to cover next bit of bind_thread */ + while (!(thread_set_first_tmask(&bind_conf->thread_set) & (1UL << bit))) bit++; - done += shards; - } + mask |= (1UL << bit); + bit++; + done += shards; + } - new_li->rx.bind_thread = thread_set_first_tmask(&bind_conf->thread_set) & mask; - new_li->rx.bind_tgroup = thread_set_first_group(&bind_conf->thread_set); - done -= todo; + new_li->rx.bind_thread = thread_set_first_tmask(&bind_conf->thread_set) & mask; + new_li->rx.bind_tgroup = thread_set_first_group(&bind_conf->thread_set); + done -= todo; - shard++; - if (shard >= shards) - break; + shard++; + if (shard >= shards) + break; - /* create another listener for new shards */ - new_li = clone_listener(li); - if (!new_li) { - ha_alert("Out of memory while trying to allocate extra listener for shard %d in %s %s\n", - shard, proxy_type_str(curproxy), curproxy->id); - cfgerr++; - err_code |= ERR_FATAL | ERR_ALERT; - goto out; - } + /* create another listener for new shards */ + new_li = clone_listener(li); + if (!new_li) { + ha_alert("Out of memory while trying to allocate extra listener for shard %d in %s %s\n", + shard, proxy_type_str(curproxy), curproxy->id); + cfgerr++; + err_code |= ERR_FATAL | ERR_ALERT; + goto out; } } }