MINOR: tinfo: make thread_set functions return nth group/mask instead of first

thread_set_first_group() and thread_set_first_tmask() were modified
and renamed to instead return the number and mask of the nth group.
Passing zero continues to return the first one, but it will be more
convenient to use this way when building shards.
This commit is contained in:
Willy Tarreau 2023-02-27 11:27:38 +01:00
parent fea8c19119
commit 7b8aac4439
3 changed files with 15 additions and 12 deletions

View File

@ -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 <n>th thread-group set in thread set
* <ts>, or zero if the set is empty or if thread numbers are only absolute.
* <n> 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 <n>th assigned thread-group in the thread
* set <ts> 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. <n> 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];

View File

@ -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 &&

View File

@ -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;
}