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];
}
/* 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++;
/* 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 &&
}
/* 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;
}