diff --git a/include/haproxy/tinfo.h b/include/haproxy/tinfo.h index 4bae4f2b3..3d10560f9 100644 --- a/include/haproxy/tinfo.h +++ b/include/haproxy/tinfo.h @@ -68,33 +68,36 @@ static inline int thread_set_is_empty(const struct thread_set *ts) return 1; } -/* returns the number starting at 1 of the first thread-group set in thread set +/* returns the number starting at 1 of the th thread-group set in thread set * , or zero if the set is empty or if thread numbers are only absolute. + * starts at zero and corresponds to the number of non-empty groups to be + * skipped (i.e. 0 returns the first one). */ -static inline int thread_set_first_group(const struct thread_set *ts) +static inline int thread_set_nth_group(const struct thread_set *ts, int n) { int i; if (ts->nbgrp) { for (i = 0; i < MAX_TGROUPS; i++) - if (ts->rel[i]) + if (ts->rel[i] && !n--) return i + 1; } return 0; } -/* returns the thread mask of the first assigned thread-group in the thread +/* returns the thread mask of the th assigned thread-group in the thread * set for relative sets, the first thread mask at all in case of absolute * sets, or zero if the set is empty. This is only used temporarily to ease the - * transition. + * transition. starts at zero and corresponds to the number of non-empty + * groups to be skipped (i.e. 0 returns the first one). */ -static inline ulong thread_set_first_tmask(const struct thread_set *ts) +static inline ulong thread_set_nth_tmask(const struct thread_set *ts, int n) { int i; if (ts->nbgrp) { for (i = 0; i < MAX_TGROUPS; i++) - if (ts->rel[i]) + if (ts->rel[i] && !n--) return ts->rel[i]; } return ts->abs[0]; diff --git a/src/cfgparse.c b/src/cfgparse.c index 06ee98097..52f40d633 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -3016,8 +3016,8 @@ init_proxies_list_stage1: } /* assign the first (and only) thread and group */ - new_li->rx.bind_thread = thread_set_first_tmask(&new_ts); - new_li->rx.bind_tgroup = thread_set_first_group(&new_ts); + new_li->rx.bind_thread = thread_set_nth_tmask(&new_ts, 0); + new_li->rx.bind_tgroup = thread_set_nth_group(&new_ts, 0); done -= todo; shard++; @@ -4458,8 +4458,8 @@ init_proxies_list_stage2: /* apply thread masks and groups to all receivers */ list_for_each_entry(li, &bind_conf->listeners, by_bind) { - li->rx.bind_thread = thread_set_first_tmask(&bind_conf->thread_set); - li->rx.bind_tgroup = thread_set_first_group(&bind_conf->thread_set); + li->rx.bind_thread = thread_set_nth_tmask(&bind_conf->thread_set, 0); + li->rx.bind_tgroup = thread_set_nth_group(&bind_conf->thread_set, 0); } if (bind_conf->xprt->prepare_bind_conf && diff --git a/src/thread.c b/src/thread.c index 0deb9202b..af27bbb60 100644 --- a/src/thread.c +++ b/src/thread.c @@ -1311,7 +1311,7 @@ int thread_resolve_group_mask(struct thread_set *ts, int defgrp, char **err) } /* update the thread_set */ - if (!thread_set_first_group(&new_ts)) { + if (!thread_set_nth_group(&new_ts, 0)) { memprintf(err, "'thread' directive only references non-existing threads"); return -1; }